continue-custom/core/util/paths.ts
Nate Sesti ff57b0080d
🪄 model dropdown, control plane (#1692)
* Nate/control plane client (#1691)

* docs: add docs and schema for "OS" provider (#1536)

* ignore .env

* fix(gui): ctx rendering w/ renderInlineAs: "" (#1541)

* ✨ use and cache imports for autocomplete (#1456)

* ✨ use and cache imports for autocomplete

* fix tsc

* fix codeqwen autocomplete leading space

* add voyage rerank-1

* feat: `--noEmit` for tsc checks in CI (#1559)

* docs: update CustomContextProvider docs (#1557)

* add stop tokens to qwen prompt

* update docs to reflect 3.5 sonnet being best

* docs: comment out unused providers (#1561)

* import Handlebars

* feat: toast notification for config updates (#1560)

* feat: toast notification for config updates

* feat: only trigger toast on config.json save

* displayRawMarkdown option

* feat: open pane on install (#1564)

* feat: open pane on activation

* comment out testing code

* update to reflect 16 stop words limit for deepseek

* feat: only trigger config update toast in vscode (#1571)

* docs(prompt-files): fix typos + clarify (#1575)

* doc: prompt file typo + clarifications

* fix: add back correct docs

* chore: add telemetry for pageviews (#1576)

* feat: update onboarding w/ embeddings model (#1570)

* chore(gui): remove unused pages

* feat: add embeddings step

* feat: update styles

* feat: copy button updates

* fix: correct pull command for embed model

* fix: remove commented code

* fix: remove commented code

* feat: simplify copy btn props

* chore: rename onboarding selection event

* feat: add provider config

* fix: undo msg name

* remove dead code

* fix: invalid mode check

* fix: remove testing logic

* docs(telemetry): add pageviews to tracking list (#1581)

* Add reranker configuration options to codebase embedding docs (#1584)

- Introduce reranker concept
- List available reranker options
- Provide configuration instructions
- Update keywords to include "reranker"

* chore: update pr template with screenshots (#1590)

* Refactor ConfirmationDialog to use SecondaryButton for cancel action (#1586)

* Added instructions for running docs server locally (#1578)

- Added NPM script method
- Added VS Code task method
- Update contributing guidelines

* Update branch policy (#1577)

- Change PR target to `dev` branch
- Update `CONTRIBUTING.md` instructions

* Consolidate example configurations into the main configuration guide (#1579)

- Moved examples to configuration.md
- Deleted the separate examples.md file
- Updated sidebar order and links
- Improved readability and structure in configuration.md

* fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582)

* Update completionProvider.ts (warning tab-autocomplete models) (#1566)

* feat: enhanced IndexingProgressBar with blinking dot feature

- Integrated BlinkingDot component
- Added STATUS_COLORS for various states
- Replaced CircleDiv with BlinkingDot in UI
- Updated status messages and layout

* small UI tweaks

* feat(gui): enhance ModelCard, ModelProviderTag, and Toggle components (#1595)

- add styling and adjustments to ModelCard
- update ModelProviderTag font size
- remove box shadow from Toggle component
- tweak icon styles in ModelCard
- improve alignment and spacing

* media query

* feat: add best experience onboarding

* fix: file rename

* stop movement on button hover by keeping same border thickness

* fix mistake in setting cursor: pointer

* fix when free trial option is shown

* Support Node.js versions below 20 for streaming response handling (#1591)

- Add fallback for Node < 20
- Implement toAsyncIterable for streaming
- Use TextDecoder for manual decoding
- Maintain existing streaming for Node 20+

* small fixes

* feat: add free trial card to onboarding (#1600)

* feat: add free trial card to onboarding

* add import

* fix hasPassedFTL

* fix /edit cancellation from UI

* feat: add `applyCodeBlock` experimental prop (#1601)

* feat: add new model styling improvements (#1609)

* feat: add new model styling improvements

* better gap size

* feat: update bug_report.yml (#1610)

* chore: update bug_report.yml

* typo fix

* feat: add labels to "Add docs" dialog (#1612)

* feat: add labels to "Add docs" dialog

* remove autofocus

* don't double load config

* small fixes

* speed up directory traversal, and use correct native path module

* option not to show config update toast

* merge air-gapped and recommended setup pages

* chore: add telemetry for full screen toggle (#1618)

* Fix headings in codebase-embeddings.md (#1617)

* mention jetbrains

* docs: update changie  (#1619)

* feat: updated changie config

* hide toc and autogenerate

* Update changelog.mdx

* link to deeper explanation of embeddings models

* ensure target="_blank" for all links in sidebar

* fix gif links in intellij README.md

* don't require rust in dependency installation

* chore: fix padding on gh button (#1620)

* chore: adjust button padding

* Update tasks.json

* escape colons in diff path

* smoother lancedb indexing reporting

* smooth progress updates for indexing

* fix tsc err

* rerank-lite-1

* remove doccs

* basic tests for VS Code extension

* improved testing of VS Code extension

* docs: add docs and schema for "OS" provider (#1536)

* ignore .env

* 🚑 fix constant warnings when onboarding with Ollama

* ✨ use and cache imports for autocomplete (#1456)

* ✨ use and cache imports for autocomplete

* fix tsc

* team analytics

* apply control plane settings

* workos auth

* ide protocol get session info

* UI for auth

* profile switching

* small fixes

* updates

* refresh tokens

* updates

* fix tsc errs

* model select in toolbar to make room for profile selector

* prod client id

* link to prod URL

* internal beta option

* profiles change listener

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
Co-authored-by: Priyash <38959321+priyashpatil@users.noreply.github.com>
Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>
Co-authored-by: YohannZe <99359799+YohannZe@users.noreply.github.com>
Co-authored-by: Dan Dascalescu <ddascalescu+github@gmail.com>

* temporary patch for type errs

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
Co-authored-by: Priyash <38959321+priyashpatil@users.noreply.github.com>
Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>
Co-authored-by: YohannZe <99359799+YohannZe@users.noreply.github.com>
Co-authored-by: Dan Dascalescu <ddascalescu+github@gmail.com>
2024-07-08 22:05:21 -07:00

305 lines
8.5 KiB
TypeScript

import * as JSONC from "comment-json";
import dotenv from "dotenv";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { defaultConfig, defaultConfigJetBrains } from "../config/default.js";
import Types from "../config/types.js";
import { IdeType, SerializedContinueConfig } from "../index.js";
dotenv.config();
const CONTINUE_GLOBAL_DIR =
process.env.CONTINUE_GLOBAL_DIR ?? path.join(os.homedir(), ".continue");
export function getContinueGlobalPath(): string {
// This is ~/.continue on mac/linux
const continuePath = CONTINUE_GLOBAL_DIR;
if (!fs.existsSync(continuePath)) {
fs.mkdirSync(continuePath);
}
return continuePath;
}
export function getSessionsFolderPath(): string {
const sessionsPath = path.join(getContinueGlobalPath(), "sessions");
if (!fs.existsSync(sessionsPath)) {
fs.mkdirSync(sessionsPath);
}
return sessionsPath;
}
export function getIndexFolderPath(): string {
const indexPath = path.join(getContinueGlobalPath(), "index");
if (!fs.existsSync(indexPath)) {
fs.mkdirSync(indexPath);
}
return indexPath;
}
export function getGlobalContextFilePath(): string {
return path.join(getIndexFolderPath(), "globalContext.json");
}
export function getSessionFilePath(sessionId: string): string {
return path.join(getSessionsFolderPath(), `${sessionId}.json`);
}
export function getSessionsListPath(): string {
const filepath = path.join(getSessionsFolderPath(), "sessions.json");
if (!fs.existsSync(filepath)) {
fs.writeFileSync(filepath, JSON.stringify([]));
}
return filepath;
}
export function getConfigJsonPath(ideType: IdeType = "vscode"): string {
const p = path.join(getContinueGlobalPath(), "config.json");
if (!fs.existsSync(p)) {
if (ideType === "jetbrains") {
fs.writeFileSync(p, JSON.stringify(defaultConfigJetBrains, null, 2));
} else {
fs.writeFileSync(p, JSON.stringify(defaultConfig, null, 2));
}
}
return p;
}
export function getConfigTsPath(): string {
const p = path.join(getContinueGlobalPath(), "config.ts");
if (!fs.existsSync(p)) {
fs.writeFileSync(
p,
`export function modifyConfig(config: Config): Config {
return config;
}`,
);
}
const typesPath = path.join(getContinueGlobalPath(), "types");
if (!fs.existsSync(typesPath)) {
fs.mkdirSync(typesPath);
}
const corePath = path.join(typesPath, "core");
if (!fs.existsSync(corePath)) {
fs.mkdirSync(corePath);
}
const packageJsonPath = path.join(getContinueGlobalPath(), "package.json");
if (!fs.existsSync(packageJsonPath)) {
fs.writeFileSync(
packageJsonPath,
JSON.stringify({
name: "continue-config",
version: "1.0.0",
description: "My Continue Configuration",
main: "config.js",
}),
);
}
fs.writeFileSync(path.join(corePath, "index.d.ts"), Types);
return p;
}
export function getConfigJsPath(): string {
// Do not create automatically
return path.join(getContinueGlobalPath(), "out", "config.js");
}
export function getTsConfigPath(): string {
const tsConfigPath = path.join(getContinueGlobalPath(), "tsconfig.json");
if (!fs.existsSync(tsConfigPath)) {
fs.writeFileSync(
tsConfigPath,
JSON.stringify(
{
compilerOptions: {
target: "ESNext",
useDefineForClassFields: true,
lib: ["DOM", "DOM.Iterable", "ESNext"],
allowJs: true,
skipLibCheck: true,
esModuleInterop: false,
allowSyntheticDefaultImports: true,
strict: true,
forceConsistentCasingInFileNames: true,
module: "System",
moduleResolution: "Node",
noEmit: false,
noEmitOnError: false,
outFile: "./out/config.js",
typeRoots: ["./node_modules/@types", "./types"],
},
include: ["./config.ts"],
},
null,
2,
),
);
}
return tsConfigPath;
}
export function devDataPath(): string {
const sPath = path.join(getContinueGlobalPath(), "dev_data");
if (!fs.existsSync(sPath)) {
fs.mkdirSync(sPath);
}
return sPath;
}
export function getDevDataSqlitePath(): string {
return path.join(devDataPath(), "devdata.sqlite");
}
export function getDevDataFilePath(fileName: string): string {
return path.join(devDataPath(), `${fileName}.jsonl`);
}
export function editConfigJson(
callback: (config: SerializedContinueConfig) => SerializedContinueConfig,
): void {
const config = fs.readFileSync(getConfigJsonPath(), "utf8");
let configJson = JSONC.parse(config);
// Check if it's an object
if (typeof configJson === "object" && configJson !== null) {
configJson = callback(configJson as any) as any;
fs.writeFileSync(getConfigJsonPath(), JSONC.stringify(configJson, null, 2));
} else {
console.warn("config.json is not a valid object");
}
}
function getMigrationsFolderPath(): string {
const migrationsPath = path.join(getContinueGlobalPath(), ".migrations");
if (!fs.existsSync(migrationsPath)) {
fs.mkdirSync(migrationsPath);
}
return migrationsPath;
}
export function migrate(
id: string,
callback: () => void,
onAlreadyComplete?: () => void,
) {
const migrationsPath = getMigrationsFolderPath();
const migrationPath = path.join(migrationsPath, id);
if (!fs.existsSync(migrationPath)) {
try {
callback();
fs.writeFileSync(migrationPath, "");
} catch (e) {
console.error(`Migration ${id} failed`, e);
}
} else if (onAlreadyComplete) {
onAlreadyComplete();
}
}
export function getIndexSqlitePath(): string {
return path.join(getIndexFolderPath(), "index.sqlite");
}
export function getLanceDbPath(): string {
return path.join(getIndexFolderPath(), "lancedb");
}
export function getTabAutocompleteCacheSqlitePath(): string {
return path.join(getIndexFolderPath(), "autocompleteCache.sqlite");
}
export function getDocsSqlitePath(): string {
return path.join(getIndexFolderPath(), "docs.sqlite");
}
export function getRemoteConfigsFolderPath(): string {
const dir = path.join(getContinueGlobalPath(), ".configs");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return dir;
}
export function getPathToRemoteConfig(remoteConfigServerUrl: string): string {
let url: URL | undefined = undefined;
try {
url =
typeof remoteConfigServerUrl !== "string" || remoteConfigServerUrl === ""
? undefined
: new URL(remoteConfigServerUrl);
} catch (e) {}
const dir = path.join(getRemoteConfigsFolderPath(), url?.hostname ?? "None");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
return dir;
}
export function internalBetaPathExists(): boolean {
const sPath = path.join(getContinueGlobalPath(), ".internal_beta");
return fs.existsSync(sPath);
}
export function getConfigJsonPathForRemote(
remoteConfigServerUrl: string,
): string {
return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.json");
}
export function getConfigJsPathForRemote(
remoteConfigServerUrl: string,
): string {
return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.js");
}
export function getContinueDotEnv(): { [key: string]: string } {
const filepath = path.join(getContinueGlobalPath(), ".env");
if (fs.existsSync(filepath)) {
return dotenv.parse(fs.readFileSync(filepath));
}
return {};
}
export function getLogsDirPath(): string {
const logsPath = path.join(getContinueGlobalPath(), "logs");
if (!fs.existsSync(logsPath)) {
fs.mkdirSync(logsPath);
}
return logsPath;
}
export function getCoreLogsPath(): string {
return path.join(getLogsDirPath(), "core.log");
}
export function getPromptLogsPath(): string {
return path.join(getLogsDirPath(), "prompt.log");
}
export function getGlobalPromptsPath(): string {
return path.join(getContinueGlobalPath(), ".prompts");
}
export function readAllGlobalPromptFiles(
folderPath: string = getGlobalPromptsPath(),
): { path: string; content: string }[] {
if (!fs.existsSync(folderPath)) {
return [];
}
const files = fs.readdirSync(folderPath);
const promptFiles: { path: string; content: string }[] = [];
files.forEach((file) => {
const filepath = path.join(folderPath, file);
const stats = fs.statSync(filepath);
if (stats.isDirectory()) {
const nestedPromptFiles = readAllGlobalPromptFiles(filepath);
promptFiles.push(...nestedPromptFiles);
} else {
const content = fs.readFileSync(filepath, "utf8");
promptFiles.push({ path: filepath, content });
}
});
return promptFiles;
}