import * as plugins from '../plugins.js'; import { AiDoc } from '../classes.aidoc.js'; import { ProjectContext } from './projectcontext.js'; export class Commit { private aiDocsRef: AiDoc; private projectDir: string; constructor(aiDocsRef: AiDoc, projectDirArg: string) { this.aiDocsRef = aiDocsRef; this.projectDir = projectDirArg; } public async build() { const projectContext = new ProjectContext(this.projectDir); const contextString = await projectContext.update(); let result = await this.aiDocsRef.openaiInstance.chat({ systemMessage: ` You create a commit message for a git commit. The commit message should be based on the files in the project. You should not include any licensing information. You should not include any personal information. Important: Answer only in valid JSON. Your answer should be parseable with JSON.parse() without modifying anything. Here is the structure of the JSON you should return: { recommendedNextVersionLevel: 'patch' | 'minor' | 'major'; // the recommended next version level of the project recommendedNextVersion: string; // the recommended next version of the project message: string; // the commit message. use conventional commits format } You are being given the files of the project. You should use them to create the commit message. Also you are given a diff `, messageHistory: [], userMessage: contextString, }); console.log(result.message); const resultObject = JSON.parse(result.message.replace('```json', '').replace('```', '')); const npmextraJson = (await projectContext.gatherFiles()).smartfilesNpmextraJSON; const npmextraJsonContent = JSON.parse(npmextraJson.contents.toString()); npmextraJsonContent.gitzone.module.commit = resultObject.message; npmextraJson.contents = Buffer.from(JSON.stringify(npmextraJsonContent, null, 2)); await npmextraJson.write(); } }