Split a text buffer into line spans. content_end excludes CR/LF so callers * can print or compare line content without newline spelling differences. */
| 5497 | * the live KV, so busy /save requests are deferred until a stable append-only |
| 5498 | * point and then executed by the worker thread. */ |
| 5499 | static bool agent_worker_save_session_now(agent_worker *w, char sha_out[41], |
| 5500 | int *tokens_out, |
| 5501 | char *err, size_t err_len) { |
| 5502 | if (!agent_worker_has_user_session(w)) { |
| 5503 | snprintf(err, err_len, "nothing to save"); |
| 5504 | return false; |
| 5505 | } |
| 5506 | if (w->image_count) { |
| 5507 | snprintf(err, err_len, |
| 5508 | "sessions containing images cannot be saved yet"); |
| 5509 | return false; |
| 5510 | } |
| 5511 | |
| 5512 | const bool text_only = w->transcript.len >= agent_worker_effective_ctx_size(w); |
| 5513 | if (!text_only && |
| 5514 | agent_worker_sync_tokens(w, &w->transcript, false, err, err_len) != 0) |
| 5515 | return false; |
| 5516 | if (!agent_mkdir_p(w->cache_dir)) { |
| 5517 | snprintf(err, err_len, "failed to create %s", w->cache_dir); |
| 5518 | return false; |
| 5519 | } |
| 5520 |
no test coverage detected