AGENTS.md support

This commit is contained in:
Nate 2025-07-13 21:48:58 -07:00
parent 6d9d6b50f8
commit b4978bf30a
3 changed files with 37 additions and 3 deletions

View file

@ -13,6 +13,7 @@ import { configureLogger } from "./logger.js";
import { MCPService } from "./mcp.js";
import { handleSlashCommands } from "./slashCommands.js";
import { streamChatResponse } from "./streamChatResponse.js";
import { constructSystemMessage } from "./systemMessage.js";
import { startTUIChat } from "./ui/index.js";
// Parse command line arguments
@ -92,7 +93,8 @@ async function chat() {
// Rules
const chatHistory: ChatCompletionMessageParam[] = [];
const systemMessage = assistant.systemMessage;
const baseSystemMessage = assistant.systemMessage;
const systemMessage = constructSystemMessage(baseSystemMessage);
if (systemMessage) {
chatHistory.push({ role: "system", content: systemMessage });
}

30
src/systemMessage.ts Normal file
View file

@ -0,0 +1,30 @@
import * as fs from "fs";
import * as path from "path";
/**
* Load and append agent configuration content to the system message if it exists
* @param baseSystemMessage - The base system message from the assistant
* @returns The enhanced system message with agent configuration content if available
*/
export function constructSystemMessage(baseSystemMessage: string): string {
const agentFiles = ["AGENTS.md", "AGENT.md", "CLAUDE.md", "CODEX.md"];
try {
for (const fileName of agentFiles) {
const filePath = path.join(process.cwd(), fileName);
if (fs.existsSync(filePath)) {
const fileContent = fs.readFileSync(filePath, "utf-8");
// Append file content to the base system message
const separator = baseSystemMessage ? "\n\n" : "";
return `${baseSystemMessage}${separator}# Repository Context from ${fileName}\n\n${fileContent}`;
}
}
} catch (error) {
// If there's any error reading the file, just return the base system message
console.warn("Warning: Could not read agent configuration file:", error);
}
return baseSystemMessage;
}

View file

@ -4,6 +4,7 @@ import { ChatCompletionMessageParam } from "openai/resources.mjs";
import React, { useEffect, useState } from "react";
import { handleSlashCommands } from "../slashCommands.js";
import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js";
import { constructSystemMessage } from "../systemMessage.js";
import { getToolDisplayName } from "../tools.js";
import LoadingAnimation from "./LoadingAnimation.js";
import ToolResultSummary from "./ToolResultSummary.js";
@ -32,7 +33,8 @@ const TUIChat: React.FC<TUIChatProps> = ({
const [chatHistory, setChatHistory] = useState<ChatCompletionMessageParam[]>(
() => {
const history: ChatCompletionMessageParam[] = [];
const systemMessage = assistant.systemMessage;
const baseSystemMessage = assistant.systemMessage;
const systemMessage = constructSystemMessage(baseSystemMessage);
if (systemMessage) {
history.push({ role: "system", content: systemMessage });
}
@ -317,4 +319,4 @@ const TUIChat: React.FC<TUIChatProps> = ({
);
};
export default TUIChat;
export default TUIChat;