mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 05:02:14 +00:00
support appending content to the system prompt via cli argument
This commit is contained in:
parent
029a04c43b
commit
ef8bb6c062
2 changed files with 62 additions and 50 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -13,6 +13,7 @@ packages/*/dist-firefox/
|
||||||
|
|
||||||
# Editor files
|
# Editor files
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.zed/
|
||||||
.idea/
|
.idea/
|
||||||
*.swp
|
*.swp
|
||||||
*.swo
|
*.swo
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ interface Args {
|
||||||
model?: string;
|
model?: string;
|
||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
systemPrompt?: string;
|
systemPrompt?: string;
|
||||||
|
appendSystemPrompt?: string;
|
||||||
thinking?: ThinkingLevel;
|
thinking?: ThinkingLevel;
|
||||||
continue?: boolean;
|
continue?: boolean;
|
||||||
resume?: boolean;
|
resume?: boolean;
|
||||||
|
|
@ -88,6 +89,8 @@ function parseArgs(args: string[]): Args {
|
||||||
result.apiKey = args[++i];
|
result.apiKey = args[++i];
|
||||||
} else if (arg === "--system-prompt" && i + 1 < args.length) {
|
} else if (arg === "--system-prompt" && i + 1 < args.length) {
|
||||||
result.systemPrompt = args[++i];
|
result.systemPrompt = args[++i];
|
||||||
|
} else if (arg === "--append-system-prompt" && i + 1 < args.length) {
|
||||||
|
result.appendSystemPrompt = args[++i];
|
||||||
} else if (arg === "--no-session") {
|
} else if (arg === "--no-session") {
|
||||||
result.noSession = true;
|
result.noSession = true;
|
||||||
} else if (arg === "--session" && i + 1 < args.length) {
|
} else if (arg === "--session" && i + 1 < args.length) {
|
||||||
|
|
@ -235,6 +238,7 @@ ${chalk.bold("Options:")}
|
||||||
--model <id> Model ID (default: gemini-2.5-flash)
|
--model <id> Model ID (default: gemini-2.5-flash)
|
||||||
--api-key <key> API key (defaults to env vars)
|
--api-key <key> API key (defaults to env vars)
|
||||||
--system-prompt <text> System prompt (default: coding assistant prompt)
|
--system-prompt <text> System prompt (default: coding assistant prompt)
|
||||||
|
--append-system-prompt <text> Append text or file contents to the system prompt
|
||||||
--mode <mode> Output mode: text (default), json, or rpc
|
--mode <mode> Output mode: text (default), json, or rpc
|
||||||
--print, -p Non-interactive mode: process prompt and exit
|
--print, -p Non-interactive mode: process prompt and exit
|
||||||
--continue, -c Continue previous session
|
--continue, -c Continue previous session
|
||||||
|
|
@ -320,19 +324,27 @@ const toolDescriptions: Record<ToolName, string> = {
|
||||||
ls: "List directory contents",
|
ls: "List directory contents",
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildSystemPrompt(customPrompt?: string, selectedTools?: ToolName[]): string {
|
function resolvePromptInput(input: string | undefined, description: string): string | undefined {
|
||||||
// Check if customPrompt is a file path that exists
|
if (!input) {
|
||||||
if (customPrompt && existsSync(customPrompt)) {
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existsSync(input)) {
|
||||||
try {
|
try {
|
||||||
customPrompt = readFileSync(customPrompt, "utf-8");
|
return readFileSync(input, "utf-8");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(chalk.yellow(`Warning: Could not read system prompt file ${customPrompt}: ${error}`));
|
console.error(chalk.yellow(`Warning: Could not read ${description} file ${input}: ${error}`));
|
||||||
// Fall through to use as literal string
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customPrompt) {
|
return input;
|
||||||
// Use custom prompt as base, then add context/datetime
|
}
|
||||||
|
|
||||||
|
function buildSystemPrompt(customPrompt?: string, selectedTools?: ToolName[], appendSystemPrompt?: string): string {
|
||||||
|
const resolvedCustomPrompt = resolvePromptInput(customPrompt, "system prompt");
|
||||||
|
const resolvedAppendPrompt = resolvePromptInput(appendSystemPrompt, "append system prompt");
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const dateTime = now.toLocaleString("en-US", {
|
const dateTime = now.toLocaleString("en-US", {
|
||||||
weekday: "long",
|
weekday: "long",
|
||||||
|
|
@ -345,7 +357,14 @@ function buildSystemPrompt(customPrompt?: string, selectedTools?: ToolName[]): s
|
||||||
timeZoneName: "short",
|
timeZoneName: "short",
|
||||||
});
|
});
|
||||||
|
|
||||||
let prompt = customPrompt;
|
const appendSection = resolvedAppendPrompt ? `\n\n${resolvedAppendPrompt}` : "";
|
||||||
|
|
||||||
|
if (resolvedCustomPrompt) {
|
||||||
|
let prompt = resolvedCustomPrompt;
|
||||||
|
|
||||||
|
if (appendSection) {
|
||||||
|
prompt += appendSection;
|
||||||
|
}
|
||||||
|
|
||||||
// Append project context files
|
// Append project context files
|
||||||
const contextFiles = loadProjectContextFiles();
|
const contextFiles = loadProjectContextFiles();
|
||||||
|
|
@ -364,18 +383,6 @@ function buildSystemPrompt(customPrompt?: string, selectedTools?: ToolName[]): s
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
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",
|
|
||||||
});
|
|
||||||
|
|
||||||
// Get absolute path to README.md
|
// Get absolute path to README.md
|
||||||
const readmePath = getReadmePath();
|
const readmePath = getReadmePath();
|
||||||
|
|
||||||
|
|
@ -453,6 +460,10 @@ Documentation:
|
||||||
- Your own documentation (including custom model setup and theme creation) is at: ${readmePath}
|
- Your own documentation (including custom model setup and theme creation) is at: ${readmePath}
|
||||||
- Read it when users ask about features, configuration, or setup, and especially if the user asks you to add a custom model or provider, or create a custom theme.`;
|
- Read it when users ask about features, configuration, or setup, and especially if the user asks you to add a custom model or provider, or create a custom theme.`;
|
||||||
|
|
||||||
|
if (appendSection) {
|
||||||
|
prompt += appendSection;
|
||||||
|
}
|
||||||
|
|
||||||
// Append project context files
|
// Append project context files
|
||||||
const contextFiles = loadProjectContextFiles();
|
const contextFiles = loadProjectContextFiles();
|
||||||
if (contextFiles.length > 0) {
|
if (contextFiles.length > 0) {
|
||||||
|
|
@ -1138,7 +1149,7 @@ export async function main(args: string[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemPrompt = buildSystemPrompt(parsed.systemPrompt, parsed.tools);
|
const systemPrompt = buildSystemPrompt(parsed.systemPrompt, parsed.tools, parsed.appendSystemPrompt);
|
||||||
|
|
||||||
// Load previous messages if continuing or resuming
|
// Load previous messages if continuing or resuming
|
||||||
// This may update initialModel if restoring from session
|
// This may update initialModel if restoring from session
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue