mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 08:01:19 +00:00
refactor: move context files to system prompt instead of user messages
- Context files now appended to system prompt - Added current date/time to system prompt - Added current working directory to system prompt - Date/time and cwd placed at end of system prompt - Updated README to reflect system prompt integration
This commit is contained in:
parent
dca3e1cc60
commit
b1c2c32e23
2 changed files with 41 additions and 24 deletions
|
|
@ -168,7 +168,7 @@ Context files are useful for:
|
||||||
- Update CHANGELOG.md for user-facing changes
|
- Update CHANGELOG.md for user-facing changes
|
||||||
```
|
```
|
||||||
|
|
||||||
Each file is injected as a separate user message at the beginning of new sessions, ensuring the AI has full project context without modifying the system prompt.
|
All context files are automatically included in the system prompt at session start, along with the current date/time and working directory. This ensures the AI has complete project context from the very first message.
|
||||||
|
|
||||||
## Image Support
|
## Image Support
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,24 @@ ${chalk.bold("Available Tools:")}
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_SYSTEM_PROMPT = `You are an expert coding assistant. You help users with coding tasks by reading files, executing commands, editing code, and writing new files.
|
function buildSystemPrompt(customPrompt?: string): string {
|
||||||
|
if (customPrompt) {
|
||||||
|
return customPrompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
const dateTime = now.toLocaleString("en-US", {
|
||||||
|
weekday: "long",
|
||||||
|
year: "numeric",
|
||||||
|
month: "long",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
second: "2-digit",
|
||||||
|
timeZoneName: "short",
|
||||||
|
});
|
||||||
|
|
||||||
|
let prompt = `You are an expert coding assistant. You help users with coding tasks by reading files, executing commands, editing code, and writing new files.
|
||||||
|
|
||||||
Available tools:
|
Available tools:
|
||||||
- read: Read file contents
|
- read: Read file contents
|
||||||
|
|
@ -145,9 +162,24 @@ Guidelines:
|
||||||
- Use edit for precise changes (old text must match exactly)
|
- Use edit for precise changes (old text must match exactly)
|
||||||
- Use write only for new files or complete rewrites
|
- Use write only for new files or complete rewrites
|
||||||
- Be concise in your responses
|
- Be concise in your responses
|
||||||
- Show file paths clearly when working with files
|
- Show file paths clearly when working with files`;
|
||||||
|
|
||||||
Current directory: ${process.cwd()}`;
|
// Append project context files
|
||||||
|
const contextFiles = loadProjectContextFiles();
|
||||||
|
if (contextFiles.length > 0) {
|
||||||
|
prompt += "\n\n# Project Context\n\n";
|
||||||
|
prompt += "The following project context files have been loaded:\n\n";
|
||||||
|
for (const { path: filePath, content } of contextFiles) {
|
||||||
|
prompt += `## ${filePath}\n\n${content}\n\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add date/time and working directory last
|
||||||
|
prompt += `\nCurrent date and time: ${dateTime}`;
|
||||||
|
prompt += `\nCurrent working directory: ${process.cwd()}`;
|
||||||
|
|
||||||
|
return prompt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Look for AGENT.md or CLAUDE.md in a directory (prefers AGENT.md)
|
* Look for AGENT.md or CLAUDE.md in a directory (prefers AGENT.md)
|
||||||
|
|
@ -407,7 +439,7 @@ export async function main(args: string[]) {
|
||||||
|
|
||||||
// Create agent
|
// Create agent
|
||||||
const model = getModel(provider, modelId);
|
const model = getModel(provider, modelId);
|
||||||
const systemPrompt = parsed.systemPrompt || DEFAULT_SYSTEM_PROMPT;
|
const systemPrompt = buildSystemPrompt(parsed.systemPrompt);
|
||||||
|
|
||||||
const agent = new Agent({
|
const agent = new Agent({
|
||||||
initialState: {
|
initialState: {
|
||||||
|
|
@ -479,27 +511,12 @@ export async function main(args: string[]) {
|
||||||
// Note: Session will be started lazily after first user+assistant message exchange
|
// Note: Session will be started lazily after first user+assistant message exchange
|
||||||
// (unless continuing/resuming, in which case it's already initialized)
|
// (unless continuing/resuming, in which case it's already initialized)
|
||||||
|
|
||||||
// Inject project context files (AGENT.md/CLAUDE.md) if not continuing/resuming
|
// Log loaded context files (they're already in the system prompt)
|
||||||
if (!parsed.continue && !parsed.resume) {
|
if (shouldPrintMessages && !parsed.continue && !parsed.resume) {
|
||||||
const contextFiles = loadProjectContextFiles();
|
const contextFiles = loadProjectContextFiles();
|
||||||
if (contextFiles.length > 0) {
|
if (contextFiles.length > 0) {
|
||||||
// Queue each context file as a separate message
|
const fileList = contextFiles.map((f) => f.path).join(", ");
|
||||||
for (const { path: filePath, content } of contextFiles) {
|
console.log(chalk.dim(`Loaded project context from: ${fileList}`));
|
||||||
await agent.queueMessage({
|
|
||||||
role: "user",
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: "text",
|
|
||||||
text: `[Project Context from ${filePath}]\n\n${content}`,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
timestamp: Date.now(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (shouldPrintMessages) {
|
|
||||||
const fileList = contextFiles.map((f) => f.path).join(", ");
|
|
||||||
console.log(chalk.dim(`Loaded project context from: ${fileList}`));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue