feat(coding-agent): add support for APPEND_SYSTEM.md to append instructions to system prompt (#716)
Co-authored-by: Jian Zhang <jzhang@yanhuangdata.com>
This commit is contained in:
@@ -573,7 +573,7 @@ Use these for:
|
|||||||
|
|
||||||
### Custom System Prompt
|
### Custom System Prompt
|
||||||
|
|
||||||
Replace the default system prompt entirely by creating a `SYSTEM.md` file:
|
Replace the default system prompt **entirely** by creating a `SYSTEM.md` file:
|
||||||
|
|
||||||
1. **Project-local:** `.pi/SYSTEM.md` (takes precedence)
|
1. **Project-local:** `.pi/SYSTEM.md` (takes precedence)
|
||||||
2. **Global:** `~/.pi/agent/SYSTEM.md` (fallback)
|
2. **Global:** `~/.pi/agent/SYSTEM.md` (fallback)
|
||||||
@@ -589,7 +589,16 @@ Focus on:
|
|||||||
- Proper formatting
|
- Proper formatting
|
||||||
```
|
```
|
||||||
|
|
||||||
The `--system-prompt` CLI flag overrides both files. Use `--append-system-prompt` to add to (rather than replace) the prompt.
|
The `--system-prompt` CLI flag overrides both files.
|
||||||
|
|
||||||
|
### Appending to the System Prompt
|
||||||
|
|
||||||
|
To add instructions to the system prompt **without** replacing the default (preserving automatic loading of `AGENTS.md` context files, skills, and tools guidelines), create an `APPEND_SYSTEM.md` file:
|
||||||
|
|
||||||
|
1. **Project-local:** `.pi/APPEND_SYSTEM.md` (takes precedence)
|
||||||
|
2. **Global:** `~/.pi/agent/APPEND_SYSTEM.md` (fallback)
|
||||||
|
|
||||||
|
The `--append-system-prompt` CLI flag overrides both files.
|
||||||
|
|
||||||
### Custom Models and Providers
|
### Custom Models and Providers
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,23 @@ function discoverSystemPromptFile(): string | undefined {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Discover APPEND_SYSTEM.md file if no CLI append system prompt was provided */
|
||||||
|
function discoverAppendSystemPromptFile(): string | undefined {
|
||||||
|
// Check project-local first: .pi/APPEND_SYSTEM.md
|
||||||
|
const projectPath = join(process.cwd(), CONFIG_DIR_NAME, "APPEND_SYSTEM.md");
|
||||||
|
if (existsSync(projectPath)) {
|
||||||
|
return projectPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to global: ~/.pi/agent/APPEND_SYSTEM.md
|
||||||
|
const globalPath = join(getAgentDir(), "APPEND_SYSTEM.md");
|
||||||
|
if (existsSync(globalPath)) {
|
||||||
|
return globalPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function buildSessionOptions(
|
function buildSessionOptions(
|
||||||
parsed: Args,
|
parsed: Args,
|
||||||
scopedModels: ScopedModel[],
|
scopedModels: ScopedModel[],
|
||||||
@@ -128,8 +145,11 @@ function buildSessionOptions(
|
|||||||
|
|
||||||
// Auto-discover SYSTEM.md if no CLI system prompt provided
|
// Auto-discover SYSTEM.md if no CLI system prompt provided
|
||||||
const systemPromptSource = parsed.systemPrompt ?? discoverSystemPromptFile();
|
const systemPromptSource = parsed.systemPrompt ?? discoverSystemPromptFile();
|
||||||
|
// Auto-discover APPEND_SYSTEM.md if no CLI append system prompt provided
|
||||||
|
const appendSystemPromptSource = parsed.appendSystemPrompt ?? discoverAppendSystemPromptFile();
|
||||||
|
|
||||||
const resolvedSystemPrompt = resolvePromptInput(systemPromptSource, "system prompt");
|
const resolvedSystemPrompt = resolvePromptInput(systemPromptSource, "system prompt");
|
||||||
const resolvedAppendPrompt = resolvePromptInput(parsed.appendSystemPrompt, "append system prompt");
|
const resolvedAppendPrompt = resolvePromptInput(appendSystemPromptSource, "append system prompt");
|
||||||
|
|
||||||
if (sessionManager) {
|
if (sessionManager) {
|
||||||
options.sessionManager = sessionManager;
|
options.sessionManager = sessionManager;
|
||||||
|
|||||||
Reference in New Issue
Block a user