2
0
Fork 0
forked from zynk/zynk

Strip opencode header from !ai responses. (0.38.3)

- Added strip_opencode_header(): removes the opencode header line (e.g. '> plan · big-pickle') and any trailing blank lines from AI responses before sending to IRC.
- Previous strip_before_double_space() approach failed because ANSI escape codes in the raw opencode output prevented strstr() from matching literal double spaces.
- New approach runs strip_formatting() first to clean up ANSI codes, then detects the '> ' prefix and strips the header line plus blank lines after it.
- Pipeline order: format strip -> header strip -> phrase strip.
- Version bumped to 0.38.3.
This commit is contained in:
Johannes Findeisen 2026-07-21 14:56:11 +02:00
commit 60a407fa2f
2 changed files with 33 additions and 16 deletions

View file

@ -1,3 +1,9 @@
2026.07.21 – Strip opencode header from !ai responses. (0.38.3)
- Added `strip_opencode_header()`: removes the opencode header line (e.g. `> plan · big-pickle`) and any trailing blank lines from AI responses before sending to IRC.
- Pipeline order: format strip → header strip → phrase strip, so ANSI codes are cleaned up first and the `> ` prefix is reliably detected.
- Version bumped to 0.38.3.
2026.07.21 – Full mode for !gitlog/!changelog, optional pull for !rebuild. (0.38.2)
- Added optional `full` keyword to `!gitlog` and `!changelog`: `!gitlog 5 full` shows full commit messages (author, date, body), `!changelog 5 full` shows the complete entry text including bullet points.

43
zynk.c
View file

@ -28,7 +28,7 @@ int asprintf(char **, const char *, ...);
/* ---- constants ---- */
#define VERSION "0.38.2"
#define VERSION "0.38.3"
#define DEFAULT_SERVER "irc.libera.chat"
#define OPENCODE_BIN "/usr/bin/opencode"
#define CLR_RESET "\033[0m"
@ -1453,20 +1453,32 @@ static void strip_formatting(char *s) {
*dst = 0;
}
// This needs to be tested more.
/*static void strip_opencode_header(char *s) {
if (!s || s[0] != '>' || s[1] != ' ') return;
char *sep = strstr(s, " \xc2\xb7 ");
if (!sep) sep = strstr(s, " · ");
if (!sep) return;
char *nl = strchr(s, '\n');
if (nl) {
nl++;
memmove(s, nl, strlen(nl) + 1);
} else {
s[0] = 0;
/*
* strip_opencode_header - Strip the opencode header line from AI output.
*
* Removes the leading header line produced by opencode (e.g.
* "> plan · big-pickle " or "> build · big-pickle ") and any blank
* lines that follow it. Must be called AFTER strip_formatting() has
* removed ANSI escape codes so the '>' prefix is at position 0.
* If the string does not start with '>', it is left unchanged.
*
* Parameters:
* s - The string to modify in-place. Must be writable.
*
* Returns: void. The string is modified in-place.
*/
static void strip_opencode_header(char *s) {
while (*s == '\n') {
memmove(s, s + 1, strlen(s));
}
}*/
if (s[0] != '>') return;
char *nl = strchr(s, '\n');
if (!nl) { s[0] = 0; return; }
char *p = nl + 1;
while (*p == '\n') p++;
size_t len = strlen(p);
memmove(s, p, len + 1);
}
/*
* has_crlf - Check if a string contains CR or LF characters.
@ -1854,9 +1866,8 @@ static void ai_child_task(Session *s, long long id, const char *agent) {
} else if (olen == 0) {
ai_set_answer(id, "AI returned an empty response");
} else {
// Needs more testing.
//strip_opencode_header(out);
strip_formatting(out);
strip_opencode_header(out);
strip_ai_phrases(out);
ai_set_answer(id, out);
db_update_lasta(out);