2
0
Fork 0
forked from zynk/zynk

Added -opencode command-line option to set the path to the opencode binary, overriding OPENCODE_BIN.

This commit is contained in:
Johannes Findeisen 2026-07-15 21:19:28 +02:00
commit 10c45492bc
2 changed files with 25 additions and 14 deletions

View file

@ -10,3 +10,4 @@
- Added !version command to report the bot's version via IRC.
- Fixed the malformed VERSION macro definition to ensure successful builds.
- Added !help command to list available bot commands.
- Added -opencode command-line option to set the path to the opencode binary, overriding OPENCODE_BIN.

38
zynk.c
View file

@ -29,17 +29,17 @@ int asprintf(char **, const char *, ...);
/* ---- constants ---- */
#define VERSION "0.31"
#define VERSION "0.32"
#define DEFAULT_SERVER "irc.libera.chat"
#define OPENCODE_BIN "/home/hanez/bin/opencode"
#define CLR_RESET "\033[0m"
#define CLR_DIM "\033[2m"
#define CLR_RED "\033[31m"
#define CLR_GREEN "\033[32m"
#define CLR_YELLOW "\033[33m"
#define CLR_BLUE "\033[34m"
#define CLR_MAGENTA "\033[35m"
#define CLR_CYAN "\033[36m"
#define OPENCODE_BIN "/usr/bin/opencode"
#define CLR_RESET "\033[0m"
#define CLR_DIM "\033[2m"
#define CLR_RED "\033[31m"
#define CLR_GREEN "\033[32m"
#define CLR_YELLOW "\033[33m"
#define CLR_BLUE "\033[34m"
#define CLR_MAGENTA "\033[35m"
#define CLR_CYAN "\033[36m"
enum {
RBUF_SZ = 16384,
@ -803,6 +803,7 @@ static char *fetch_forecast(const char *city_url, const char *city_display) {
static volatile pid_t pending_ai_pid;
static volatile long long pending_ai_id;
static const char *g_opencode_bin = OPENCODE_BIN;
static void ai_child_task(Session *s, long long id, const char *agent) {
signal(SIGALRM, SIG_DFL);
@ -866,9 +867,9 @@ static void ai_child_task(Session *s, long long id, const char *agent) {
int dn = open("/dev/null", O_WRONLY);
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
if (agent)
execl(OPENCODE_BIN, "opencode", "run", "--dangerously-skip-permissions", "--agent", agent, combined, (char *)NULL);
execl(g_opencode_bin, "opencode", "run", "--dangerously-skip-permissions", "--agent", agent, combined, (char *)NULL);
else
execl(OPENCODE_BIN, "opencode", "run", "--dangerously-skip-permissions", "--agent", "plan", combined, (char *)NULL);
execl(g_opencode_bin, "opencode", "run", "--dangerously-skip-permissions", "--agent", "plan", combined, (char *)NULL);
_exit(127);
}
close(ai_pipe[1]);
@ -1482,7 +1483,7 @@ static void irc_feed(Session *s, const char *data, int len) {
static void usage(const char *prog) {
fprintf(stderr,
"Usage: %s [-ssl] [-server host] [-port p] [-nick n] [-join c]\n"
"Usage: %s [-ssl] [-server host] [-port p] [-nick n] [-join c] [-opencode path]\n"
" -h This help\n"
" -noverify Skip TLS certificate verification\n"
" -server host IRC server (default: %s)\n"
@ -1490,11 +1491,12 @@ static void usage(const char *prog) {
" -pass p Server password\n"
" -nick n Nickname (default: zynk<PID>)\n"
" -join c Auto-join channels (comma-sep, default: #zynk)\n"
" -opencode p Path to opencode binary (default: %s)\n"
"\n"
"Zynk commands:\n"
" zynk foo = bar Store 'bar' under key 'foo'\n"
" zynk foo Retrieve value for 'foo'\n",
prog, DEFAULT_SERVER, DEF_PORT);
prog, DEFAULT_SERVER, DEF_PORT, OPENCODE_BIN);
}
/* ---- reconnect ---- */
@ -1543,6 +1545,7 @@ int main(int argc, char **argv) {
const char *nick = NULL;
char passbuf[256] = "";
char joinbuf[256] = "#zynk";
g_opencode_bin = OPENCODE_BIN;
int pos = 0;
log_stamp(); fprintf(stderr, CLR_CYAN "[zynk] starting up" CLR_RESET "\n");
for (int i = 1; i < argc; i++) {
@ -1567,6 +1570,9 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[i], "-join") == 0) {
if (++i >= argc) { usage(argv[0]); return 1; }
snprintf(joinbuf, sizeof joinbuf, "%s", argv[i]);
} else if (strcmp(argv[i], "-opencode") == 0) {
if (++i >= argc) { usage(argv[0]); return 1; }
g_opencode_bin = argv[i];
} else if (strcmp(argv[i], "-noverify") == 0) {
tls_verify = 0;
} else {
@ -1597,6 +1603,10 @@ int main(int argc, char **argv) {
fprintf(stderr, CLR_RED "Invalid IRC argument" CLR_RESET "\n");
return 1;
}
if (!g_opencode_bin || !*g_opencode_bin) {
fprintf(stderr, CLR_RED "Invalid opencode path" CLR_RESET "\n");
return 1;
}
if (db_init() < 0) {
fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n");
sqlite_cleanup();