mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 13:03:42 +00:00
feat: support file paths for --system-prompt option
- Check if --system-prompt argument is a valid file path - Load file contents if it exists, otherwise use as literal text - Works in both interactive and single-shot modes - Project context and datetime still appended automatically - Document in README with examples
This commit is contained in:
parent
79ee33c3fc
commit
a0fa254107
2 changed files with 46 additions and 3 deletions
|
|
@ -251,8 +251,12 @@ Model ID. Default: `claude-sonnet-4-5`
|
|||
**--api-key <key>**
|
||||
API key (overrides environment variables)
|
||||
|
||||
**--system-prompt <text>**
|
||||
Custom system prompt (overrides default coding assistant prompt)
|
||||
**--system-prompt <text|file>**
|
||||
Custom system prompt. Can be:
|
||||
- Inline text: `--system-prompt "You are a helpful assistant"`
|
||||
- File path: `--system-prompt ./my-prompt.txt`
|
||||
|
||||
If the argument is a valid file path, the file contents will be used as the system prompt. Otherwise, the text is used directly. Project context files and datetime are automatically appended.
|
||||
|
||||
**--mode <mode>**
|
||||
Output mode for non-interactive usage. Options:
|
||||
|
|
|
|||
|
|
@ -132,8 +132,47 @@ ${chalk.bold("Available Tools:")}
|
|||
}
|
||||
|
||||
function buildSystemPrompt(customPrompt?: string): string {
|
||||
// Check if customPrompt is a file path that exists
|
||||
if (customPrompt && existsSync(customPrompt)) {
|
||||
try {
|
||||
customPrompt = readFileSync(customPrompt, "utf-8");
|
||||
} catch (error) {
|
||||
console.error(chalk.yellow(`Warning: Could not read system prompt file ${customPrompt}: ${error}`));
|
||||
// Fall through to use as literal string
|
||||
}
|
||||
}
|
||||
|
||||
if (customPrompt) {
|
||||
return customPrompt;
|
||||
// Use custom prompt as base, then add context/datetime
|
||||
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 = customPrompt;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue