Skip to content

Commit 1c43796

Browse files
committed
fix: markdown rules and top level agents
1 parent c75262e commit 1c43796

File tree

13 files changed

+222
-215
lines changed

13 files changed

+222
-215
lines changed

core/config/markdown/loadCodebaseRules.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,24 @@ export class CodebaseRulesCache {
2626
}
2727
async update(ide: IDE, uri: string) {
2828
const content = await ide.readFile(uri);
29-
const { relativePathOrBasename } = findUriInDirs(
29+
const workspaceDirs = await ide.getWorkspaceDirs();
30+
const { relativePathOrBasename, foundInDir } = findUriInDirs(
3031
uri,
31-
await ide.getWorkspaceDirs(),
32+
workspaceDirs,
33+
);
34+
if (!foundInDir) {
35+
console.warn(
36+
`Failed to load codebase rule ${uri}: URI not found in workspace`,
37+
);
38+
}
39+
const rule = markdownToRule(
40+
content,
41+
{
42+
uriType: "file",
43+
fileUri: uri,
44+
},
45+
relativePathOrBasename,
3246
);
33-
const rule = markdownToRule(content, {
34-
uriType: "file",
35-
fileUri: relativePathOrBasename,
36-
});
3747
const ruleWithSource: RuleWithSource = {
3848
...rule,
3949
source: "colocated-markdown",
@@ -75,20 +85,32 @@ export async function loadCodebaseRules(ide: IDE): Promise<{
7585
for (const filePath of rulesMdFiles) {
7686
try {
7787
const content = await ide.readFile(filePath);
78-
const { relativePathOrBasename } = findUriInDirs(
88+
const { relativePathOrBasename, foundInDir, uri } = findUriInDirs(
7989
filePath,
8090
await ide.getWorkspaceDirs(),
8191
);
82-
const rule = markdownToRule(content, {
83-
uriType: "file",
84-
fileUri: relativePathOrBasename,
85-
});
92+
if (foundInDir) {
93+
const lastSlashIndex = relativePathOrBasename.lastIndexOf("/");
94+
const parentDir = relativePathOrBasename.substring(0, lastSlashIndex);
95+
const rule = markdownToRule(
96+
content,
97+
{
98+
uriType: "file",
99+
fileUri: uri,
100+
},
101+
parentDir,
102+
);
86103

87-
rules.push({
88-
...rule,
89-
source: "colocated-markdown",
90-
sourceFile: filePath,
91-
});
104+
rules.push({
105+
...rule,
106+
source: "colocated-markdown",
107+
sourceFile: filePath,
108+
});
109+
} else {
110+
console.warn(
111+
`Failed to load codebase rule ${uri}: URI not found in workspace dirs`,
112+
);
113+
}
92114
} catch (e) {
93115
errors.push({
94116
fatal: false,

core/config/markdown/loadMarkdownRules.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
markdownToRule,
44
} from "@continuedev/config-yaml";
55
import { IDE, RuleWithSource } from "../..";
6-
import { findUriInDirs, joinPathsToUri } from "../../util/uri";
6+
import { joinPathsToUri } from "../../util/uri";
77
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
88

99
export const SUPPORTED_AGENT_FILES = ["AGENTS.md", "AGENT.md", "CLAUDE.md"];
@@ -25,20 +25,24 @@ export async function loadMarkdownRules(ide: IDE): Promise<{
2525
let agentFileFound = false;
2626
for (const fileName of SUPPORTED_AGENT_FILES) {
2727
try {
28-
const agentFilePath = joinPathsToUri(workspaceDir, fileName);
29-
const agentContent = await ide.readFile(agentFilePath);
28+
const agentFileUri = joinPathsToUri(workspaceDir, fileName);
29+
const exists = await ide.fileExists(agentFileUri);
30+
if (exists) {
31+
const agentContent = await ide.readFile(agentFileUri);
32+
33+
const rule = markdownToRule(agentContent, {
34+
uriType: "file",
35+
fileUri: agentFileUri,
36+
});
37+
rules.push({
38+
...rule,
39+
source: "agent-file",
40+
sourceFile: agentFileUri,
41+
alwaysApply: true,
42+
});
43+
agentFileFound = true;
44+
}
3045

31-
const rule = markdownToRule(agentContent, {
32-
uriType: "file",
33-
fileUri: agentFilePath,
34-
});
35-
rules.push({
36-
...rule,
37-
source: "agent-file",
38-
sourceFile: agentFilePath,
39-
alwaysApply: true,
40-
});
41-
agentFileFound = true;
4246
break; // Use the first found agent file in this workspace
4347
} catch (e) {
4448
// File doesn't exist or can't be read, continue to next file
@@ -63,13 +67,9 @@ export async function loadMarkdownRules(ide: IDE): Promise<{
6367
// Process each markdown file
6468
for (const file of mdFiles) {
6569
try {
66-
const { relativePathOrBasename } = findUriInDirs(
67-
file.path,
68-
await ide.getWorkspaceDirs(),
69-
);
7070
const rule = markdownToRule(file.content, {
7171
uriType: "file",
72-
fileUri: relativePathOrBasename,
72+
fileUri: file.path,
7373
});
7474
rules.push({ ...rule, source: "rules-block", sourceFile: file.path });
7575
} catch (e) {

core/config/profile/doLoadConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { getControlPlaneEnv } from "../../control-plane/env.js";
2828
import { PolicySingleton } from "../../control-plane/PolicySingleton";
2929
import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
3030
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
31+
import { initSlashCommand } from "../../promptFiles/initPrompt";
3132
import { getConfigDependentToolDefinitions } from "../../tools";
3233
import { encodeMCPToolUri } from "../../tools/callTool";
3334
import { getMCPToolName } from "../../tools/mcpToolName";
@@ -171,6 +172,8 @@ export default async function doLoadConfig(options: {
171172
}
172173
}
173174

175+
newConfig.slashCommands.push(initSlashCommand);
176+
174177
const proxyContextProvider = newConfig.contextProviders?.find(
175178
(cp) => cp.description.title === "continue-proxy",
176179
);

core/config/yaml/yamlToContinueConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ export function convertYamlMcpConfigToInternalMcpOptions(
4848
if ("command" in config) {
4949
const { args, command, cwd, env, type } = config;
5050
const stdioOptions: InternalStdioMcpOptions = {
51+
...shared,
5152
type,
5253
command,
5354
args,
5455
cwd,
5556
env,
56-
...shared,
5757
};
5858
return stdioOptions;
5959
}
@@ -62,13 +62,13 @@ export function convertYamlMcpConfigToInternalMcpOptions(
6262
const httpSseConfig:
6363
| InternalStreamableHttpMcpOptions
6464
| InternalSseMcpOptions = {
65+
...shared,
6566
type,
6667
url,
6768
requestOptions: mergeConfigYamlRequestOptions(
6869
requestOptions,
6970
globalRequestOptions,
7071
),
71-
...shared,
7272
};
7373
return httpSseConfig;
7474
}

core/promptFiles/getPromptFiles.ts

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,6 @@ import { walkDir } from "../indexing/walkDir";
44
import { readAllGlobalPromptFiles } from "../util/paths";
55
import { joinPathsToUri } from "../util/uri";
66

7-
// The hardcoded init prompt content
8-
const INIT_PROMPT_CONTENT = `name: Init
9-
description: Initialize Codebase
10-
---
11-
You are an expert development assistant. Your task is to create a comprehensive CONTINUE.md project guide for the user's codebase to help them and their team better understand and work with the project.
12-
13-
## Step 1: Check Required Tools
14-
First, verify that you have access to the necessary tools:
15-
- builtin_file_glob_search: To discover project files
16-
- builtin_read_file: To analyze file contents
17-
- builtin_ls: To explore directory structure
18-
- builtin_create_new_file: To generate the CONTINUE.md file
19-
20-
If any of these tools are unavailable, inform the user that they need to activate them and enable "Agent Mode" in Continue before proceeding.
21-
22-
## Step 2: Project Analysis
23-
Analyze the project structure and key files to understand:
24-
- The programming languages and frameworks used
25-
- The overall architecture and organization
26-
- Key components and their responsibilities
27-
- Important configuration files
28-
- Build/deployment system
29-
30-
## Step 3: Generate CONTINUE.md
31-
Create a comprehensive CONTINUE.md file in the .continue/rules/ directory with the following sections:
32-
33-
1. **Project Overview**
34-
- Brief description of the project's purpose
35-
- Key technologies used
36-
- High-level architecture
37-
38-
2. **Getting Started**
39-
- Prerequisites (required software, dependencies)
40-
- Installation instructions
41-
- Basic usage examples
42-
- Running tests
43-
44-
3. **Project Structure**
45-
- Overview of main directories and their purpose
46-
- Key files and their roles
47-
- Important configuration files
48-
49-
4. **Development Workflow**
50-
- Coding standards or conventions
51-
- Testing approach
52-
- Build and deployment process
53-
- Contribution guidelines
54-
55-
5. **Key Concepts**
56-
- Domain-specific terminology
57-
- Core abstractions
58-
- Design patterns used
59-
60-
6. **Common Tasks**
61-
- Step-by-step guides for frequent development tasks
62-
- Examples of common operations
63-
64-
7. **Troubleshooting**
65-
- Common issues and their solutions
66-
- Debugging tips
67-
68-
8. **References**
69-
- Links to relevant documentation
70-
- Important resources
71-
72-
Make sure your analysis is thorough but concise. Focus on information that would be most helpful to developers working on the project. If certain information isn't available from the codebase, make reasonable assumptions but mark these sections as needing verification.
73-
74-
## Step 4: Finalize
75-
After creating the .continue/rules/CONTINUE.md file, provide a summary of what you've created and remind the user to:
76-
1. Review and edit the file as needed
77-
2. Commit it to their repository to share with their team
78-
3. Explain that Continue will automatically load this file into context when working with the project
79-
80-
Also inform the user that they can create additional rules.md files in subdirectories for more specific documentation related to those components.`;
81-
827
export const DEFAULT_PROMPTS_FOLDER_V2 = ".continue/prompts";
838

849
export async function getPromptFilesFromDir(
@@ -134,17 +59,8 @@ export async function getAllPromptFiles(
13459
// Also read from ~/.continue/prompts
13560
promptFiles.push(...readAllGlobalPromptFiles());
13661

137-
// Add hardcoded init prompt
138-
promptFiles.push({
139-
path: "builtin:/init.prompt",
140-
content: INIT_PROMPT_CONTENT,
141-
});
142-
14362
return await Promise.all(
14463
promptFiles.map(async (file) => {
145-
if (file.path.startsWith("builtin:")) {
146-
return file;
147-
}
14864
const content = await ide.readFile(file.path);
14965
return { path: file.path, content };
15066
}),

core/promptFiles/initPrompt.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { SlashCommandWithSource } from "..";
2+
3+
// Prompt for init slash command
4+
export const INIT_PROMPT_CONTENT = `
5+
You are an expert development assistant. Your task is to create a comprehensive CONTINUE.md project guide for the user's codebase to help them and their team better understand and work with the project.
6+
7+
## Step 1: Check Required Tools
8+
First, verify that you have access to the necessary tools:
9+
- builtin_file_glob_search: To discover project files
10+
- builtin_read_file: To analyze file contents
11+
- builtin_ls: To explore directory structure
12+
- builtin_create_new_file: To generate the CONTINUE.md file
13+
14+
If any of these tools are unavailable, inform the user that they need to activate them and enable "Agent Mode" in Continue before proceeding.
15+
16+
## Step 2: Project Analysis
17+
Analyze the project structure and key files to understand:
18+
- The programming languages and frameworks used
19+
- The overall architecture and organization
20+
- Key components and their responsibilities
21+
- Important configuration files
22+
- Build/deployment system
23+
24+
## Step 3: Generate CONTINUE.md
25+
Create a comprehensive CONTINUE.md file in the .continue/rules/ directory with the following sections:
26+
27+
1. **Project Overview**
28+
- Brief description of the project's purpose
29+
- Key technologies used
30+
- High-level architecture
31+
32+
2. **Getting Started**
33+
- Prerequisites (required software, dependencies)
34+
- Installation instructions
35+
- Basic usage examples
36+
- Running tests
37+
38+
3. **Project Structure**
39+
- Overview of main directories and their purpose
40+
- Key files and their roles
41+
- Important configuration files
42+
43+
4. **Development Workflow**
44+
- Coding standards or conventions
45+
- Testing approach
46+
- Build and deployment process
47+
- Contribution guidelines
48+
49+
5. **Key Concepts**
50+
- Domain-specific terminology
51+
- Core abstractions
52+
- Design patterns used
53+
54+
6. **Common Tasks**
55+
- Step-by-step guides for frequent development tasks
56+
- Examples of common operations
57+
58+
7. **Troubleshooting**
59+
- Common issues and their solutions
60+
- Debugging tips
61+
62+
8. **References**
63+
- Links to relevant documentation
64+
- Important resources
65+
66+
Make sure your analysis is thorough but concise. Focus on information that would be most helpful to developers working on the project. If certain information isn't available from the codebase, make reasonable assumptions but mark these sections as needing verification.
67+
68+
## Step 4: Finalize
69+
After creating the .continue/rules/CONTINUE.md file, provide a summary of what you've created and remind the user to:
70+
1. Review and edit the file as needed
71+
2. Commit it to their repository to share with their team
72+
3. Explain that Continue will automatically load this file into context when working with the project
73+
74+
Also inform the user that they can create additional rules.md files in subdirectories for more specific documentation related to those components.
75+
`.trim();
76+
77+
export const initSlashCommand: SlashCommandWithSource = {
78+
name: "Init",
79+
description: "Initialize Codebase",
80+
source: "built-in",
81+
prompt: INIT_PROMPT_CONTENT,
82+
};

0 commit comments

Comments
 (0)