UNPKG

sensai

Version:

Because even AI needs a master

60 lines (59 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "default", { enumerable: true, get: function() { return _default; } }); const _promises = require("node:fs/promises"); const _nodepath = require("node:path"); const _nodechild_process = require("node:child_process"); const _constants = require("../constants"); const _default = async (options)=>{ const { prompt, agent } = options; if (!prompt) { throw new Error("A prompt is required to create a project."); } // project generated by agent try { switch(agent){ case _constants.EXTERNAL_AGENT.CLAUDE: await createClaudeProject(prompt); break; } } catch (error) { console.log(error); throw error; } }; /** * Create instructions for `claude-code` to scaffold a project base * on the provided prompt. */ const createClaudeProject = async (prompt)=>{ const root = process.cwd(); const instructions = await (0, _promises.readFile)((0, _nodepath.join)(__dirname, "../../../llms.txt"), "utf-8"); await scaffold((0, _nodepath.join)(root, ".claude/commands/sensai.md"), `You are a very strong software engineer with expert knowledge of the framework Sensai. You will be asked to generate code managed by Sensai.\n\n ${instructions}`); // will throw error if claude code is not installed run(`claude "/project:sensai ${prompt}"`); }; /** * Execute a command in the current working directory and return the output. */ const run = (command)=>{ (0, _nodechild_process.execSync)(command, { cwd: process.cwd(), stdio: "inherit", encoding: "utf-8" }); }; /** * Simple util to create a file with the given content and recursively create * the directories leading to the file. */ const scaffold = async (filePath, content)=>{ await (0, _promises.mkdir)((0, _nodepath.dirname)(filePath), { recursive: true }); await (0, _promises.writeFile)(filePath, content, "utf-8"); };