Automatically switch to act/build mode when running code instructions.
This commit is contained in:
parent
56a733ddfa
commit
23404bdc49
1 changed files with 23 additions and 9 deletions
32
calc.c
32
calc.c
|
|
@ -729,6 +729,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 volatile const char *pending_ai_agent;
|
||||
|
||||
static void ai_child_task(Session *s, long long id) {
|
||||
signal(SIGALRM, SIG_DFL);
|
||||
|
|
@ -753,10 +754,19 @@ static void ai_child_task(Session *s, long long id) {
|
|||
int have_history = 0;
|
||||
for (int i = 0; i < MAX_HISTORY; i++) { if (history[i]) { have_history = 1; break; } }
|
||||
char prefix[2048];
|
||||
int plen = snprintf(prefix, sizeof prefix,
|
||||
"Your name is calc. Answer briefly. Answer in English when asked in English, answer in German when asked in German. Never use the wrong language. Max 800 chars. Never execute anything. Don't access files. "
|
||||
"No disclaimers or AI-sounding phrases. No markdown/formatting. "
|
||||
"Just answer directly.");
|
||||
int plen;
|
||||
if (pending_ai_agent) {
|
||||
plen = snprintf(prefix, sizeof prefix,
|
||||
"Your name is calc. You are a coding assistant in a project. Execute code changes as requested. "
|
||||
"Make real file edits and run commands as needed. Answer in English when asked in English, answer in German when asked in German. "
|
||||
"Max 2000 chars. No disclaimers or AI-sounding phrases. No markdown/formatting. "
|
||||
"Just make the changes directly and confirm what you did.");
|
||||
} else {
|
||||
plen = snprintf(prefix, sizeof prefix,
|
||||
"Your name is calc. Answer briefly. Answer in English when asked in English, answer in German when asked in German. Never use the wrong language. Max 800 chars. Never execute anything. Don't access files. "
|
||||
"No disclaimers or AI-sounding phrases. No markdown/formatting. "
|
||||
"Just answer directly.");
|
||||
}
|
||||
if (have_history) {
|
||||
plen += snprintf(prefix + plen, sizeof prefix - plen,
|
||||
" My recent answers for context (only use if absolutely necessary): ");
|
||||
|
|
@ -779,7 +789,10 @@ static void ai_child_task(Session *s, long long id) {
|
|||
close(ai_pipe[1]);
|
||||
int dn = open("/dev/null", O_WRONLY);
|
||||
if (dn >= 0) { dup2(dn, STDERR_FILENO); close(dn); }
|
||||
execl(OPENCODE_BIN, "opencode", "run", "--dangerously-skip-permissions", combined, (char *)NULL);
|
||||
if (pending_ai_agent)
|
||||
execl(OPENCODE_BIN, "opencode", "run", "--dangerously-skip-permissions", "--agent", pending_ai_agent, combined, (char *)NULL);
|
||||
else
|
||||
execl(OPENCODE_BIN, "opencode", "run", "--dangerously-skip-permissions", combined, (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
close(ai_pipe[1]);
|
||||
|
|
@ -807,7 +820,7 @@ static void ai_child_task(Session *s, long long id) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
static void ai_ask(Session *s, const char *question, const char *reply_target, const char *src_nick) {
|
||||
static void ai_ask(Session *s, const char *question, const char *reply_target, const char *src_nick, const char *agent) {
|
||||
if (rate_limit_check(src_nick) < 0) return;
|
||||
if (pending_ai_pid > 0) {
|
||||
irc_msg(s, reply_target, "Already processing an AI query, please wait.");
|
||||
|
|
@ -824,6 +837,7 @@ static void ai_ask(Session *s, const char *question, const char *reply_target, c
|
|||
if (pid == 0) { ai_child_task(s, id); }
|
||||
pending_ai_pid = pid;
|
||||
pending_ai_id = id;
|
||||
pending_ai_agent = agent;
|
||||
log_stamp(); fprintf(stderr, CLR_BLUE "AI started (PID %d, ID %lld) from %s:" CLR_RESET " %s\n", pid, id, src_nick, question);
|
||||
}
|
||||
|
||||
|
|
@ -1095,7 +1109,7 @@ static int cmd_ai(Session *s, const char *msg, const char *reply_target, const c
|
|||
char *end = question + strlen(question);
|
||||
while (end > question && end[-1] == ' ') end--;
|
||||
*end = 0;
|
||||
ai_ask(s, question, reply_target, src_nick);
|
||||
ai_ask(s, question, reply_target, src_nick, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -1122,7 +1136,7 @@ static int cmd_code(Session *s, const char *msg, const char *reply_target, const
|
|||
char *end = question + strlen(question);
|
||||
while (end > question && end[-1] == ' ') end--;
|
||||
*end = 0;
|
||||
ai_ask(s, question, reply_target, src_nick);
|
||||
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;
|
||||
}
|
||||
|
|
@ -1160,7 +1174,7 @@ static void cmd_greeting_or_chat(Session *s, const char *msg, const char *reply_
|
|||
return;
|
||||
}
|
||||
if (cmd != msg) {
|
||||
ai_ask(s, cmd, reply_target, src_nick);
|
||||
ai_ask(s, cmd, reply_target, src_nick, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue