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

Function agent_bash_poll

ds4_agent.c:6773–6804  ·  view source on GitHub ↗

Drain available output, notice process exit, and enforce timeout. This is * called opportunistically by status/wait/compaction instead of a background * reaper thread, keeping all bash job state owned by the agent worker. */

Source from the content-addressed store, hash-verified

6771 agent_line_spans old_spans = {0};
6772 agent_line_spans new_spans = {0};
6773 agent_split_lines(old_data, old_len, &old_spans);
6774 agent_split_lines(new_data, new_len, &new_spans);
6775 bool ok = old_spans.len > 0;
6776 if (ok) {
6777 size_t old_last = edit_offset;
6778 if (replaced_len > 0) old_last = edit_offset + replaced_len - 1;
6779 if (old_last >= old_len) old_last = old_len ? old_len - 1 : 0;
6780 if (start_line) *start_line = agent_line_for_offset(&old_spans, edit_offset);
6781 if (end_line) *end_line = agent_line_for_offset(&old_spans, old_last);
6782 if (delta) *delta = new_spans.len - old_spans.len;
6783 }
6784 agent_line_spans_free(&old_spans);
6785 agent_line_spans_free(&new_spans);
6786 return ok;
6787}
6788
6789static void agent_edit_result_append_context(agent_buf *b,
6790 const char *path,
6791 const char *data, size_t len,
6792 int anchor_start,
6793 int anchor_end);
6794
6795static char *agent_edit_result(const char *path,
6796 int start_line, int end_line, int delta,
6797 const char *new_data, size_t new_len,
6798 const char *kind) {
6799 agent_buf b = {.limit = AGENT_TOOL_MAX_BYTES};
6800 char msg[PATH_MAX + 180];
6801 snprintf(msg, sizeof(msg), "Edited %s using %s\n", path, kind);
6802 agent_buf_puts(&b, msg);
6803 if (start_line > 0 && end_line >= start_line) {
6804 snprintf(msg, sizeof(msg),
6805 "Touched old lines %d-%d; current post-edit context follows.\n",
6806 start_line, end_line);
6807 agent_buf_puts(&b, msg);

Callers 3

agent_bash_observationFunction · 0.85
agent_bash_refresh_forFunction · 0.85

Calls 4

agent_bash_drainFunction · 0.85
agent_bash_finalizeFunction · 0.85
now_secFunction · 0.70

Tested by

no test coverage detected