Added -opencode command-line option to set the path to the opencode binary, overriding OPENCODE_BIN.
This commit is contained in:
parent
999814e5df
commit
10c45492bc
2 changed files with 25 additions and 14 deletions
|
|
@ -10,3 +10,4 @@
|
||||||
- Added !version command to report the bot's version via IRC.
|
- Added !version command to report the bot's version via IRC.
|
||||||
- Fixed the malformed VERSION macro definition to ensure successful builds.
|
- Fixed the malformed VERSION macro definition to ensure successful builds.
|
||||||
- Added !help command to list available bot commands.
|
- 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
38
zynk.c
|
|
@ -29,17 +29,17 @@ int asprintf(char **, const char *, ...);
|
||||||
|
|
||||||
/* ---- constants ---- */
|
/* ---- constants ---- */
|
||||||
|
|
||||||
#define VERSION "0.31"
|
#define VERSION "0.32"
|
||||||
#define DEFAULT_SERVER "irc.libera.chat"
|
#define DEFAULT_SERVER "irc.libera.chat"
|
||||||
#define OPENCODE_BIN "/home/hanez/bin/opencode"
|
#define OPENCODE_BIN "/usr/bin/opencode"
|
||||||
#define CLR_RESET "\033[0m"
|
#define CLR_RESET "\033[0m"
|
||||||
#define CLR_DIM "\033[2m"
|
#define CLR_DIM "\033[2m"
|
||||||
#define CLR_RED "\033[31m"
|
#define CLR_RED "\033[31m"
|
||||||
#define CLR_GREEN "\033[32m"
|
#define CLR_GREEN "\033[32m"
|
||||||
#define CLR_YELLOW "\033[33m"
|
#define CLR_YELLOW "\033[33m"
|
||||||
#define CLR_BLUE "\033[34m"
|
#define CLR_BLUE "\033[34m"
|
||||||
#define CLR_MAGENTA "\033[35m"
|
#define CLR_MAGENTA "\033[35m"
|
||||||
#define CLR_CYAN "\033[36m"
|
#define CLR_CYAN "\033[36m"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
RBUF_SZ = 16384,
|
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 pid_t pending_ai_pid;
|
||||||
static volatile long long pending_ai_id;
|
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) {
|
static void ai_child_task(Session *s, long long id, const char *agent) {
|
||||||
signal(SIGALRM, SIG_DFL);
|
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);
|
int dn = open("/dev/null", O_WRONLY);
|
||||||
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
|
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
|
||||||
if (agent)
|
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
|
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);
|
_exit(127);
|
||||||
}
|
}
|
||||||
close(ai_pipe[1]);
|
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) {
|
static void usage(const char *prog) {
|
||||||
fprintf(stderr,
|
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"
|
" -h This help\n"
|
||||||
" -noverify Skip TLS certificate verification\n"
|
" -noverify Skip TLS certificate verification\n"
|
||||||
" -server host IRC server (default: %s)\n"
|
" -server host IRC server (default: %s)\n"
|
||||||
|
|
@ -1490,11 +1491,12 @@ static void usage(const char *prog) {
|
||||||
" -pass p Server password\n"
|
" -pass p Server password\n"
|
||||||
" -nick n Nickname (default: zynk<PID>)\n"
|
" -nick n Nickname (default: zynk<PID>)\n"
|
||||||
" -join c Auto-join channels (comma-sep, default: #zynk)\n"
|
" -join c Auto-join channels (comma-sep, default: #zynk)\n"
|
||||||
|
" -opencode p Path to opencode binary (default: %s)\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Zynk commands:\n"
|
"Zynk commands:\n"
|
||||||
" zynk foo = bar Store 'bar' under key 'foo'\n"
|
" zynk foo = bar Store 'bar' under key 'foo'\n"
|
||||||
" zynk foo Retrieve value for 'foo'\n",
|
" zynk foo Retrieve value for 'foo'\n",
|
||||||
prog, DEFAULT_SERVER, DEF_PORT);
|
prog, DEFAULT_SERVER, DEF_PORT, OPENCODE_BIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---- reconnect ---- */
|
/* ---- reconnect ---- */
|
||||||
|
|
@ -1543,6 +1545,7 @@ int main(int argc, char **argv) {
|
||||||
const char *nick = NULL;
|
const char *nick = NULL;
|
||||||
char passbuf[256] = "";
|
char passbuf[256] = "";
|
||||||
char joinbuf[256] = "#zynk";
|
char joinbuf[256] = "#zynk";
|
||||||
|
g_opencode_bin = OPENCODE_BIN;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
log_stamp(); fprintf(stderr, CLR_CYAN "[zynk] starting up" CLR_RESET "\n");
|
log_stamp(); fprintf(stderr, CLR_CYAN "[zynk] starting up" CLR_RESET "\n");
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
|
|
@ -1567,6 +1570,9 @@ int main(int argc, char **argv) {
|
||||||
} else if (strcmp(argv[i], "-join") == 0) {
|
} else if (strcmp(argv[i], "-join") == 0) {
|
||||||
if (++i >= argc) { usage(argv[0]); return 1; }
|
if (++i >= argc) { usage(argv[0]); return 1; }
|
||||||
snprintf(joinbuf, sizeof joinbuf, "%s", argv[i]);
|
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) {
|
} else if (strcmp(argv[i], "-noverify") == 0) {
|
||||||
tls_verify = 0;
|
tls_verify = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1597,6 +1603,10 @@ int main(int argc, char **argv) {
|
||||||
fprintf(stderr, CLR_RED "Invalid IRC argument" CLR_RESET "\n");
|
fprintf(stderr, CLR_RED "Invalid IRC argument" CLR_RESET "\n");
|
||||||
return 1;
|
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) {
|
if (db_init() < 0) {
|
||||||
fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n");
|
fprintf(stderr, CLR_RED "DB init failed" CLR_RESET "\n");
|
||||||
sqlite_cleanup();
|
sqlite_cleanup();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue