buildSystemPrompt function

String buildSystemPrompt(
  1. SessionContext context, {
  2. String? customInstructions,
})

Builds the system prompt for the coding agent.

The prompt is assembled from fixed guidance sections followed by the session's environment, git snapshot, and project instructions. The user's --system_prompt is appended last so it can override the defaults.

Implementation

String buildSystemPrompt(SessionContext context, {String? customInstructions}) {
  final custom = customInstructions?.trim();
  return <String>[
    _identity,
    _doingTasks,
    _codeQuality,
    _verification,
    _toolUsage,
    _toneAndStyle,
    _safety,
    _environment(context),
    if (context.gitSnapshot != null) _gitStatus(context.gitSnapshot!),
    if (context.instructionFiles.isNotEmpty) _projectInstructions(context.instructionFiles),
    if (custom != null && custom.isNotEmpty) '# Additional instructions\n\n$custom',
  ].join('\n\n');
}