diff --git a/packages/coding-agent/README.md b/packages/coding-agent/README.md index e1d644a6..6434edc4 100644 --- a/packages/coding-agent/README.md +++ b/packages/coding-agent/README.md @@ -251,8 +251,12 @@ Model ID. Default: `claude-sonnet-4-5` **--api-key ** API key (overrides environment variables) -**--system-prompt ** -Custom system prompt (overrides default coding assistant prompt) +**--system-prompt ** +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 ** Output mode for non-interactive usage. Options: diff --git a/packages/coding-agent/src/main.ts b/packages/coding-agent/src/main.ts index ba3750b7..c8a3200f 100644 --- a/packages/coding-agent/src/main.ts +++ b/packages/coding-agent/src/main.ts @@ -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();