relaycode
Version:
A developer assistant that automates applying code changes from LLMs.
25 lines (20 loc) • 2.74 kB
JavaScript
import {promises}from'fs';import y from'path';import {findConfig,getProjectId,createConfig,getStateDirectory}from'../core/config';import {logger,isEnoentError,getErrorMessage}from'../utils/logger';import {CONFIG_FILE_NAME_JSON,STATE_DIRECTORY_NAME,GITIGNORE_FILE_NAME,GITIGNORE_COMMENT}from'../utils/constants';import t from'chalk';const h=e=>`
${t.green("\u2705 relaycode has been initialized for this project.")}
Configuration file created: ${t.cyan(CONFIG_FILE_NAME_JSON)}
Project ID: ${t.cyan(e)}
${t.bold("Next steps:")}
${t.gray("1.")} (Optional) Open ${t.cyan(CONFIG_FILE_NAME_JSON)} to customize settings. The config is organized into sections:
- In ${t.yellow("'watcher'")}, you can set ${t.yellow("'preferredStrategy'")} to control AI patch generation ('auto', 'standard-diff', 'search-replace', etc.).
- In ${t.yellow("'git'")}, you can enable ${t.yellow("'git.autoGitBranch'")} to create a new branch for each transaction.
- In ${t.yellow("'patch'")}, you can configure the linter, pre/post commands, and approval behavior.
${t.gray("2.")} Run ${t.magenta("'relay watch'")} in your terminal. This will start the service and display the system prompt tailored to your configuration.
${t.gray("3.")} Copy the system prompt provided by ${t.magenta("'relay watch'")} and paste it into your AI assistant's "System Prompt" or "Custom Instructions".
`,w=async e=>{const n=y.join(e,GITIGNORE_FILE_NAME),a=`
${GITIGNORE_COMMENT}
/${STATE_DIRECTORY_NAME}/
`;try{let o=await promises.readFile(n,"utf-8");o.includes(STATE_DIRECTORY_NAME)||(o+=a,await promises.writeFile(n,o),logger.info(`Updated ${t.cyan(GITIGNORE_FILE_NAME)} to ignore ${t.cyan(STATE_DIRECTORY_NAME)}/`));}catch(o){isEnoentError(o)?(await promises.writeFile(n,a.trim()),logger.info(`Created ${t.cyan(GITIGNORE_FILE_NAME)} and added ${t.cyan(STATE_DIRECTORY_NAME)}/`)):logger.error(`Failed to update ${t.cyan(GITIGNORE_FILE_NAME)}: ${getErrorMessage(o)}`);}},M=async(e=process.cwd())=>{if(logger.info("Initializing relaycode in this project..."),await findConfig(e)){logger.warn("Configuration file already exists. Initialization skipped."),logger.log(`
To use relaycode, please run ${t.magenta("'relay watch'")}.
It will display a system prompt to copy into your LLM assistant.
You can review your configuration in your existing config file.
`);return}const a=await getProjectId(e);await createConfig(a,e),logger.success(`Created configuration file: ${t.cyan(CONFIG_FILE_NAME_JSON)}`),await promises.mkdir(y.join(getStateDirectory(e),"transaction"),{recursive:true}),logger.success(`Created state directory: ${STATE_DIRECTORY_NAME}/`),await w(e),logger.log(h(a));};export{M as initCommand};//# sourceMappingURL=init.js.map
//# sourceMappingURL=init.js.map