writeAgentsMd method
Future<GuidelineWriteStatus>
writeAgentsMd(
- String projectPath,
- List<
String> skillNames, { - AgentType agent = AgentType.claudeCode,
- required ProjectContext context,
Write AGENTS.md file with smart merge
Generates AGENTS.md content using the GuidelineComposer and smart merges with existing content if the file exists.
Parameters:
projectPath: Root path of the ServerPod projectskillNames: List of skill names to include in guidelinesagent: Agent type to generate guidelines for (defaults to claudeCode)context: Project context information
Throws GuidelineWriteException if writing fails. Returns GuidelineWriteStatus indicating the result.
Implementation
Future<GuidelineWriteStatus> writeAgentsMd(
String projectPath,
List<String> skillNames, {
AgentType agent = AgentType.claudeCode,
required ProjectContext context,
}) async {
try {
// Generate content using composer
final content = await composer.composeForAgent(
agent,
skillNames,
context,
);
final agentsFile = File(p.join(projectPath, 'AGENTS.md'));
if (await agentsFile.exists()) {
// Smart merge with existing content
final existing = await agentsFile.readAsString();
final merged = _mergeAgentsMd(existing, content);
// Check if content changed
if (merged == existing) {
return GuidelineWriteStatus.noop;
}
await agentsFile.writeAsString(merged);
return GuidelineWriteStatus.replaced;
} else {
// Create new file
await agentsFile.writeAsString(content);
return GuidelineWriteStatus.created;
}
} catch (e) {
throw GuidelineWriteException(
'Failed to write AGENTS.md: $e',
p.join(projectPath, 'AGENTS.md'),
);
}
}