diff --git a/.changeset/sharp-trams-smash.md b/.changeset/sharp-trams-smash.md new file mode 100644 index 000000000..6e9357a80 --- /dev/null +++ b/.changeset/sharp-trams-smash.md @@ -0,0 +1,5 @@ +--- +'@dexto/tui': patch +--- + +Add `/init` interactive command that analyzes the codebase and generates an `AGENTS.md` file with build/lint/test commands and code style guidelines. diff --git a/packages/tui/src/containers/OverlayContainer.tsx b/packages/tui/src/containers/OverlayContainer.tsx index e5eaae62e..1ea1acf35 100644 --- a/packages/tui/src/containers/OverlayContainer.tsx +++ b/packages/tui/src/containers/OverlayContainer.tsx @@ -1239,10 +1239,6 @@ export const OverlayContainer = forwardRef ({ ...prev, historyIndex: -1 })); - // Show user message for the executed command - const userMessage = createUserMessage(commandText); - setMessages((prev) => [...prev, userMessage]); - setUi((prev) => ({ ...prev, isProcessing: true, isCancelling: false })); const { CommandService } = await import('../services/CommandService.js'); @@ -1256,6 +1252,20 @@ export const OverlayContainer = forwardRef ({ ...prev, isProcessing: false })); + if (onSubmitPromptCommand) { + await onSubmitPromptCommand(commandText); + } + return; + } + + // Show user message for non-streaming commands + const userMessage = createUserMessage(commandText); + setMessages((prev) => [...prev, userMessage]); + if (result.type === 'output' && result.output) { const output = result.output; setMessages((prev) => [ @@ -1308,7 +1318,7 @@ export const OverlayContainer = forwardRef CommandDefinition[]): Co * Note: The help command is created separately to avoid circular dependencies */ export const generalCommands: CommandDefinition[] = [ + { + name: 'init', + description: 'Analyze this codebase and create an AGENTS.md file', + usage: '/init', + category: 'General', + handler: async ( + _args: string[], + _agent: DextoAgent, + _ctx: CommandContext + ): Promise => { + const cwd = process.cwd(); + const prompt = `Please analyze this codebase and create an AGENTS.md file at ${cwd}/AGENTS.md containing: +1. Build/lint/test commands - especially for running a single test +2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc. + +The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 150 lines long. + +If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include them. + +If there is already an AGENTS.md at ${cwd}/AGENTS.md, improve it instead of creating it from scratch.`; + + return createSendMessageMarker(prompt); + }, + }, { name: 'shell', description: 'Execute shell command directly (use !command as shortcut)',