MCPcopy Create free account
hub / github.com/antirez/ds4 / agent_worker_init

Function agent_worker_init

ds4_agent.c:9421–9466  ·  view source on GitHub ↗

Initialize the worker, cache directory, sysprompt checkpoint path, trace file, * and model thread. After this returns, all DS4 session mutation happens on * the worker thread. */

Source from the content-addressed store, hash-verified

9419 return isatty(STDOUT_FILENO) != 0;
9420}
9421
9422static char *agent_format_user_prompt_echo(const char *text) {
9423 agent_buf b = {0};
9424 if (stdout_is_tty()) {
9425 agent_buf_puts(&b, "\x1b[1;91m*\x1b[1;97m ");
9426 agent_buf_puts(&b, text);
9427 agent_buf_puts(&b, "\x1b[0m\n\n");
9428 } else {
9429 agent_buf_puts(&b, "* ");
9430 agent_buf_puts(&b, text);
9431 agent_buf_puts(&b, "\n\n");
9432 }
9433 return agent_buf_take(&b);
9434}
9435
9436static void agent_echo_user_prompt(const char *text) {
9437 char *msg = agent_format_user_prompt_echo(text);
9438 printf("%s", msg);
9439 fflush(stdout);
9440 free(msg);
9441}
9442
9443/* ============================================================================
9444 * Terminal Prompt, Status Footer, And Async Output Rendering
9445 * ============================================================================
9446 */
9447
9448static void agent_format_ctx_size(int ctx_size, char *buf, size_t len);
9449#define AGENT_INPUT_INITIAL_BUFLEN 4096
9450#define AGENT_INPUT_MAX_BUFLEN (1024*1024)
9451#define AGENT_STATUS_STYLE_START "\x1b[48;5;238;38;5;252m"
9452#define AGENT_STATUS_STYLE_END "\x1b[0m"
9453#define AGENT_STATUS_BAR_FILL "\x1b[48;5;238;38;5;201;1m"
9454#define AGENT_QUEUE_STYLE "\x1b[38;5;87;1m"
9455#define AGENT_STATUS_REDRAW_INTERVAL_SEC 0.20
9456#define AGENT_PROGRESS_BAR_WIDTH 32
9457#define AGENT_PROGRESS_BAR_MAX_BYTES 256
9458
9459static void agent_progress_append(char *buf, size_t len, size_t *pos,
9460 const char *s) {
9461 if (len == 0 || *pos >= len - 1) return;
9462 size_t avail = len - *pos;
9463 int n = snprintf(buf + *pos, avail, "%s", s);
9464 if (n <= 0) return;
9465 if ((size_t)n >= avail) *pos = len - 1;
9466 else *pos += (size_t)n;
9467}
9468
9469static void build_prompt_text(const agent_status *st, char *buf, size_t len) {

Callers 2

run_agentFunction · 0.85

Calls 6

set_nonblockFunction · 0.85
ds4_session_createFunction · 0.85
agent_default_cache_dirFunction · 0.85
agent_mkdir_pFunction · 0.85
ds4_web_createFunction · 0.85
ds4_kvstore_path_joinFunction · 0.85

Tested by

no test coverage detected