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

Function agent_worker_switch_session

ds4_agent.c:5364–5423  ·  view source on GitHub ↗

Load a saved session KV into the live transcript and optionally replay recent * history for the human. */

Source from the content-addressed store, hash-verified

5362 const char *m = agent_history_next_marker(p, end, &mark, &mark_len);
5363 if (!m) break;
5364 const char *content = m + mark_len;
5365 agent_history_mark next_mark = AGENT_HISTORY_MARK_NONE;
5366 size_t next_len = 0;
5367 const char *next = agent_history_next_marker(content, end,
5368 &next_mark, &next_len);
5369 const char *content_end = next ? next : end;
5370 const char *tp = content, *te = content_end;
5371 agent_history_trim(&tp, &te);
5372
5373 if (mark == AGENT_HISTORY_MARK_USER) {
5374 if (agent_history_is_tool_user(tp, te)) {
5375 const char *payload_start = tp;
5376 const char *payload_end = te;
5377 (void)agent_history_tool_result_payload(&payload_start,
5378 &payload_end);
5379 if (color) {
5380 const char *s = "\x1b[90mTool result:\n";
5381 agent_publish(w, s, strlen(s));
5382 } else {
5383 agent_publish(w, "Tool result:\n", strlen("Tool result:\n"));
5384 }
5385 agent_history_publish_limited(w, payload_start, payload_end,
5386 12, 3000);
5387 if (color) agent_publish(w, "\x1b[0m", 4);
5388 } else {
5389 if (color) {
5390 const char *s = "\x1b[1;32mUser:\x1b[0m\n";
5391 agent_publish(w, s, strlen(s));
5392 } else {
5393 agent_publish(w, "User:\n", strlen("User:\n"));
5394 }
5395 agent_history_publish_limited(w, tp, te, 24, 6000);
5396 }
5397 } else if (mark == AGENT_HISTORY_MARK_ASSISTANT) {
5398 if (color) {
5399 const char *s = "\x1b[1;37mAssistant:\x1b[0m\n";
5400 agent_publish(w, s, strlen(s));
5401 } else {
5402 agent_publish(w, "Assistant:\n", strlen("Assistant:\n"));
5403 }
5404 agent_history_render_assistant(w, tp, te);
5405 }
5406 p = content_end;
5407 }
5408
5409 if (color) {
5410 const char *s = "\x1b[90m--- end history ---\x1b[0m\n";
5411 agent_publish(w, s, strlen(s));
5412 } else {
5413 agent_publish(w, "--- end history ---\n", strlen("--- end history ---\n"));
5414 }
5415}
5416
5417/* Render recent saved transcript text without mutating the live session. */
5418static bool agent_worker_show_history(agent_worker *w, int user_turns,
5419 char *err, size_t err_len) {
5420 if (!worker_is_idle(w)) {
5421 snprintf(err, err_len, "model is busy");

Callers 1

run_agentFunction · 0.85

Calls 11

worker_is_idleFunction · 0.85
ds4_kvstore_entry_freeFunction · 0.85
agent_kv_load_pathFunction · 0.85
ds4_tokens_freeFunction · 0.85
agent_wake_lockedFunction · 0.85
xstrdupFunction · 0.70

Tested by

no test coverage detected