fix: file create/delete config loading triggers
This commit is contained in:
parent
b5300b592f
commit
92c866f647
2 changed files with 94 additions and 69 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { BLOCK_TYPES } from "@continuedev/config-yaml";
|
||||
import ignore from "ignore";
|
||||
import * as URI from "uri-js";
|
||||
import { IDE } from "..";
|
||||
|
|
@ -6,12 +7,32 @@ import {
|
|||
DEFAULT_IGNORE_FILETYPES,
|
||||
} from "../indexing/ignore";
|
||||
import { walkDir } from "../indexing/walkDir";
|
||||
import { RULES_MARKDOWN_FILENAME } from "../llm/rules/constants";
|
||||
import { getGlobalFolderWithName } from "../util/paths";
|
||||
import { localPathToUri } from "../util/pathToUri";
|
||||
import { joinPathsToUri } from "../util/uri";
|
||||
import { getUriPathBasename, joinPathsToUri } from "../util/uri";
|
||||
import { SYSTEM_PROMPT_DOT_FILE } from "./getWorkspaceContinueRuleDotFiles";
|
||||
export function isContinueConfigRelatedUri(uri: string): boolean {
|
||||
return (
|
||||
uri.endsWith(".continuerc.json") ||
|
||||
uri.endsWith(".prompt") ||
|
||||
uri.endsWith("AGENTS.md") ||
|
||||
uri.endsWith("AGENT.md") ||
|
||||
uri.endsWith("CLAUDE.md") ||
|
||||
uri.endsWith(SYSTEM_PROMPT_DOT_FILE) ||
|
||||
(uri.includes(".continue") &&
|
||||
(uri.endsWith(".yaml") ||
|
||||
uri.endsWith(".yml") ||
|
||||
uri.endsWith(".json"))) ||
|
||||
[...BLOCK_TYPES, "agents", "assistants"].some((blockType) =>
|
||||
uri.includes(`.continue/${blockType}`),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function isLocalDefinitionFile(uri: string): boolean {
|
||||
if (!uri.endsWith(".yaml") && !uri.endsWith(".yml") && !uri.endsWith(".md")) {
|
||||
export function isContinueAgentConfigFile(uri: string): boolean {
|
||||
const isYaml = uri.endsWith(".yaml") || uri.endsWith(".yml");
|
||||
if (!isYaml) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +43,10 @@ export function isLocalDefinitionFile(uri: string): boolean {
|
|||
);
|
||||
}
|
||||
|
||||
export function isColocatedRulesFile(uri: string): boolean {
|
||||
return getUriPathBasename(uri) === RULES_MARKDOWN_FILENAME;
|
||||
}
|
||||
|
||||
async function getDefinitionFilesInDir(
|
||||
ide: IDE,
|
||||
dir: string,
|
||||
|
|
|
|||
132
core/core.ts
132
core/core.ts
|
|
@ -8,7 +8,6 @@ import {
|
|||
prevFilepaths,
|
||||
} from "./autocomplete/util/openedFilesLruCache";
|
||||
import { ConfigHandler } from "./config/ConfigHandler";
|
||||
import { SYSTEM_PROMPT_DOT_FILE } from "./config/getWorkspaceContinueRuleDotFiles";
|
||||
import { addModel, deleteModel } from "./config/util";
|
||||
import { getAuthUrlForTokenPage } from "./control-plane/auth/index";
|
||||
import { getControlPlaneEnv } from "./control-plane/env";
|
||||
|
|
@ -49,11 +48,15 @@ import {
|
|||
type IDE,
|
||||
} from ".";
|
||||
|
||||
import { BLOCK_TYPES, ConfigYaml } from "@continuedev/config-yaml";
|
||||
import { ConfigYaml } from "@continuedev/config-yaml";
|
||||
import { getDiffFn, GitDiffCache } from "./autocomplete/snippets/gitDiffCache";
|
||||
import { stringifyMcpPrompt } from "./commands/slash/mcpSlashCommand";
|
||||
import { createNewAssistantFile } from "./config/createNewAssistantFile";
|
||||
import { isLocalDefinitionFile } from "./config/loadLocalAssistants";
|
||||
import {
|
||||
isColocatedRulesFile,
|
||||
isContinueAgentConfigFile,
|
||||
isContinueConfigRelatedUri,
|
||||
} from "./config/loadLocalAssistants";
|
||||
import { CodebaseRulesCache } from "./config/markdown/loadCodebaseRules";
|
||||
import {
|
||||
setupLocalConfig,
|
||||
|
|
@ -69,7 +72,6 @@ import { streamDiffLines } from "./edit/streamDiffLines";
|
|||
import { shouldIgnore } from "./indexing/shouldIgnore";
|
||||
import { walkDirCache } from "./indexing/walkDir";
|
||||
import { LLMLogger } from "./llm/logger";
|
||||
import { RULES_MARKDOWN_FILENAME } from "./llm/rules/constants";
|
||||
import { llmStreamChat } from "./llm/streamChat";
|
||||
import { BeforeAfterDiff } from "./nextEdit/context/diffFormatting";
|
||||
import { processSmallEdit } from "./nextEdit/context/processSmallEdit";
|
||||
|
|
@ -80,17 +82,6 @@ import { OnboardingModes } from "./protocol/core";
|
|||
import type { IMessenger, Message } from "./protocol/messenger";
|
||||
import { shareSession } from "./util/historyUtils";
|
||||
import { Logger } from "./util/Logger.js";
|
||||
import { getUriPathBasename } from "./util/uri";
|
||||
|
||||
const hasRulesFiles = (uris: string[]): boolean => {
|
||||
for (const uri of uris) {
|
||||
const filename = getUriPathBasename(uri);
|
||||
if (filename === RULES_MARKDOWN_FILENAME) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export class Core {
|
||||
configHandler: ConfigHandler;
|
||||
|
|
@ -875,40 +866,65 @@ export class Core {
|
|||
};
|
||||
|
||||
on("files/created", async ({ data }) => {
|
||||
if (data?.uris?.length) {
|
||||
walkDirCache.invalidate();
|
||||
void refreshIfNotIgnored(data.uris);
|
||||
if (!data?.uris?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasRulesFiles(data.uris)) {
|
||||
const rulesCache = CodebaseRulesCache.getInstance();
|
||||
await Promise.all(
|
||||
data.uris.map((uri) => rulesCache.update(this.ide, uri)),
|
||||
);
|
||||
await this.configHandler.reloadConfig("Rules file created");
|
||||
}
|
||||
// If it's a local assistant being created, we want to reload all assistants so it shows up in the list
|
||||
let localAssistantCreated = false;
|
||||
for (const uri of data.uris) {
|
||||
if (isLocalDefinitionFile(uri)) {
|
||||
localAssistantCreated = true;
|
||||
}
|
||||
}
|
||||
if (localAssistantCreated) {
|
||||
await this.configHandler.refreshAll("Local assistant file created");
|
||||
}
|
||||
walkDirCache.invalidate();
|
||||
void refreshIfNotIgnored(data.uris);
|
||||
|
||||
const colocatedRulesUris = data.uris.filter(isColocatedRulesFile);
|
||||
const nonColocatedRuleUris = data.uris.filter(
|
||||
(uri) => !isColocatedRulesFile(uri),
|
||||
);
|
||||
if (colocatedRulesUris) {
|
||||
const rulesCache = CodebaseRulesCache.getInstance();
|
||||
Promise.all(
|
||||
colocatedRulesUris.map((uri) => rulesCache.update(this.ide, uri)),
|
||||
).then(() => {
|
||||
void this.configHandler.reloadConfig("Codebase rule file created");
|
||||
});
|
||||
}
|
||||
|
||||
// If it's a local agent being created, we want to reload all agent so it shows up in the list
|
||||
if (nonColocatedRuleUris.some(isContinueAgentConfigFile)) {
|
||||
await this.configHandler.refreshAll("Local assistant file created");
|
||||
} else if (nonColocatedRuleUris.some(isContinueConfigRelatedUri)) {
|
||||
await this.configHandler.reloadConfig(
|
||||
".continue config-related file created",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
on("files/deleted", async ({ data }) => {
|
||||
if (data?.uris?.length) {
|
||||
walkDirCache.invalidate();
|
||||
void refreshIfNotIgnored(data.uris);
|
||||
if (!data?.uris?.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasRulesFiles(data.uris)) {
|
||||
const rulesCache = CodebaseRulesCache.getInstance();
|
||||
data.uris.forEach((uri) => rulesCache.remove(uri));
|
||||
await this.configHandler.reloadConfig("Codebase rule file deleted");
|
||||
}
|
||||
walkDirCache.invalidate();
|
||||
void refreshIfNotIgnored(data.uris);
|
||||
|
||||
const colocatedRulesUris = data.uris.filter(isColocatedRulesFile);
|
||||
const nonColocatedRuleUris = data.uris.filter(
|
||||
(uri) => !isColocatedRulesFile(uri),
|
||||
);
|
||||
|
||||
if (colocatedRulesUris) {
|
||||
const rulesCache = CodebaseRulesCache.getInstance();
|
||||
Promise.all(
|
||||
colocatedRulesUris.map((uri) => rulesCache.remove(uri)),
|
||||
).then(() => {
|
||||
void this.configHandler.reloadConfig("Codebase rule file deleted");
|
||||
});
|
||||
}
|
||||
|
||||
// If it's a local agent being deleted, we want to reload all agent so it disappears from the list
|
||||
if (nonColocatedRuleUris.some(isContinueAgentConfigFile)) {
|
||||
await this.configHandler.refreshAll("Local assistant file deleted");
|
||||
} else if (nonColocatedRuleUris.some(isContinueConfigRelatedUri)) {
|
||||
await this.configHandler.reloadConfig(
|
||||
".continue config-related file deleted",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -1237,10 +1253,9 @@ export class Core {
|
|||
const diffCache = GitDiffCache.getInstance(getDiffFn(this.ide));
|
||||
diffCache.invalidate();
|
||||
walkDirCache.invalidate(); // safe approach for now - TODO - only invalidate on relevant changes
|
||||
const currentProfileUri =
|
||||
this.configHandler.currentProfile?.profileDescription.uri ?? "";
|
||||
for (const uri of data.uris) {
|
||||
const currentProfileUri =
|
||||
this.configHandler.currentProfile?.profileDescription.uri ?? "";
|
||||
|
||||
if (URI.equal(uri, currentProfileUri)) {
|
||||
// Trigger a toast notification to provide UI feedback that config has been updated
|
||||
const showToast =
|
||||
|
|
@ -1260,26 +1275,7 @@ export class Core {
|
|||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
uri.endsWith(".continuerc.json") ||
|
||||
uri.endsWith(".prompt") ||
|
||||
uri.endsWith("AGENTS.md") ||
|
||||
uri.endsWith("AGENT.md") ||
|
||||
uri.endsWith("CLAUDE.md") ||
|
||||
uri.endsWith(SYSTEM_PROMPT_DOT_FILE) ||
|
||||
(uri.includes(".continue") &&
|
||||
(uri.endsWith(".yaml") ||
|
||||
uri.endsWith(".yml") ||
|
||||
uri.endsWith(".json"))) ||
|
||||
BLOCK_TYPES.some((blockType) =>
|
||||
uri.includes(`.continue/${blockType}`),
|
||||
)
|
||||
) {
|
||||
await this.configHandler.reloadConfig(
|
||||
"Config-related file updated: continuerc, prompt, local block, etc",
|
||||
);
|
||||
} else if (uri.endsWith(RULES_MARKDOWN_FILENAME)) {
|
||||
if (isColocatedRulesFile(uri)) {
|
||||
try {
|
||||
const codebaseRulesCache = CodebaseRulesCache.getInstance();
|
||||
void codebaseRulesCache.update(this.ide, uri).then(() => {
|
||||
|
|
@ -1288,6 +1284,10 @@ export class Core {
|
|||
} catch (e) {
|
||||
Logger.error(`Failed to update codebase rule: ${e}`);
|
||||
}
|
||||
} else if (isContinueConfigRelatedUri(uri)) {
|
||||
await this.configHandler.reloadConfig(
|
||||
"Local config-related file updated",
|
||||
);
|
||||
} else if (
|
||||
uri.endsWith(".continueignore") ||
|
||||
uri.endsWith(".gitignore")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue