#ifndef CMD_CODE_H #define CMD_CODE_H #include "zynk.h" /* * cmd_code - Handle the "!code " command for AI code changes. * * Requires channel op and must be used in a channel (not PM). Wraps the * instruction with context ("[CODE CHANGE REQUEST from op nick in #chan]") * and passes it to ai_ask() with agent="build", which gives the AI full * file-editing and command-execution capabilities. After the AI responds, * try_compile_and_restart() is triggered to auto-deploy if compilation * succeeds. Rate-limited. * * Parameters: * s - The IRC session. * msg - The raw message text. * reply_target - Channel or nick to reply to. * src_nick - The nick of the user who sent the command. * tgt - The message target (channel or nick). * * Returns: 1 if matched, 0 otherwise. */ int cmd_code(Session *s, const char *msg, const char *reply_target, const char *src_nick, const char *tgt) { if (strncmp(msg, "!code", 5) != 0) return 0; if (msg[5] != ' ' && msg[5] != '\0') return 0; if (tgt[0] != '#') { irc_msg(s, reply_target, "!code can only be used in a channel"); return 1; } if (!chan_is_op(tgt, src_nick)) { irc_msg(s, reply_target, "You need to be a channel op to use !code"); return 1; } const char *rest = msg[5] == ' ' ? msg + 6 : ""; while (*rest == ' ') rest++; if (!*rest) { irc_msg(s, reply_target, "Usage: !code "); return 1; } char question[2048]; snprintf(question, sizeof question, "[CODE CHANGE REQUEST from op %s in %s] %s", src_nick, tgt, rest); char *end = question + strlen(question); while (end > question && end[-1] == ' ') end--; *end = 0; ai_ask(s, question, reply_target, src_nick, "build"); log_stamp(); fprintf(stderr, CLR_RED "CODE %s from %s (op in %s):" CLR_RESET " %s\n", reply_target, src_nick, tgt, rest); return 1; } #endif