This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository edi.

View the commit online.

commit 008635572c631c073c4933f90699c4130219d10f
Author: Alastair Poole <[email protected]>
AuthorDate: Thu Apr 16 21:59:28 2026 +0100

    ai: fix writing files.
---
 src/bin/edi_agent.c              |  35 +++++-
 src/bin/edi_agent_parse.c        |  19 +++-
 src/bin/edi_aipanel.c            | 233 ++++++++++++++++++++++++++++++++++++---
 src/tests/edi_test_agent_parse.c |  36 +++++-
 4 files changed, 297 insertions(+), 26 deletions(-)

diff --git a/src/bin/edi_agent.c b/src/bin/edi_agent.c
index a4b532a..194e433 100644
--- a/src/bin/edi_agent.c
+++ b/src/bin/edi_agent.c
@@ -52,9 +52,9 @@ enum
 static const Edi_Agent_Provider _edi_agent_providers[] =
 {
    { "google_codex", "Google Codex", "https://generativelanguage.googleapis.com/v1beta/models", "gemini-2.5-flash" },
-   { "local_http", "Local HTTP Agent", "http://127.0.0.1:11434/v1/chat/completions", "qwen2.5-coder:latest" },
-   { "microsoft_copilot", "Microsoft Copilot", "https://api.githubcopilot.com/chat/completions", "gpt-4.1-mini" },
-   { "openai_compatible", "OpenAI Compatible", "https://api.openai.com/v1/chat/completions", "gpt-4.1-mini" }
+   { "local_http", "Local HTTP Agent", "http://127.0.0.1:11434/v1/responses", "qwen2.5-coder:latest" },
+   { "microsoft_copilot", "Microsoft Copilot", "https://api.githubcopilot.com/v1/responses", "gpt-4.1-mini" },
+   { "openai_compatible", "OpenAI Compatible", "https://api.openai.com/v1/responses", "gpt-4.1-mini" }
 };
 
 static const char *_edi_agent_models_google_codex[] =
@@ -464,6 +464,10 @@ _edi_agent_models_url_build(const Edi_Project_Config *config, const char *provid
         marker = strstr(eina_strbuf_string_get(url), "/v1/chat/completions");
         if (!marker)
           marker = strstr(eina_strbuf_string_get(url), "/chat/completions");
+        if (!marker)
+          marker = strstr(eina_strbuf_string_get(url), "/v1/responses");
+        if (!marker)
+          marker = strstr(eina_strbuf_string_get(url), "/responses");
         if (marker)
           eina_strbuf_remove(url, marker - eina_strbuf_string_get(url), eina_strbuf_length_get(url));
         if (eina_strbuf_length_get(url) == 0 ||
@@ -474,6 +478,8 @@ _edi_agent_models_url_build(const Edi_Project_Config *config, const char *provid
    else
      {
         marker = strstr(eina_strbuf_string_get(url), "/chat/completions");
+        if (!marker)
+          marker = strstr(eina_strbuf_string_get(url), "/responses");
         if (marker)
           {
              eina_strbuf_remove(url, marker - eina_strbuf_string_get(url), eina_strbuf_length_get(url));
@@ -938,7 +944,9 @@ edi_agent_request_send_stream(const char *prompt, Edi_Agent_Token_Cb token_cb,
    provider_id = provider->id;
 
    if (!strcmp(provider_id, "google_codex") && endpoint &&
-       (strstr(endpoint, "api.openai.com/") || strstr(endpoint, "/chat/completions")))
+      (strstr(endpoint, "api.openai.com/") ||
+       strstr(endpoint, "/chat/completions") ||
+       strstr(endpoint, "/responses")))
      provider_id = "openai_compatible";
 
    if (!model || !model[0] || !edi_agent_provider_model_supported(provider_id, model))
@@ -977,9 +985,26 @@ edi_agent_request_send_stream(const char *prompt, Edi_Agent_Token_Cb token_cb,
      }
    else
      {
+        const char *marker;
+
         eina_strbuf_append(url, endpoint);
+        marker = strstr(eina_strbuf_string_get(url), "/v1/chat/completions");
+        if (marker)
+          {
+             eina_strbuf_remove(url, marker - eina_strbuf_string_get(url), eina_strbuf_length_get(url));
+             eina_strbuf_append(url, "/v1/responses");
+          }
+        else
+          {
+             marker = strstr(eina_strbuf_string_get(url), "/chat/completions");
+             if (marker)
+               {
+                  eina_strbuf_remove(url, marker - eina_strbuf_string_get(url), eina_strbuf_length_get(url));
+                  eina_strbuf_append(url, "/responses");
+               }
+          }
         eina_strbuf_append_printf(payload,
-                                  "{\"model\":\"%s\",\"stream\":%s,\"messages\":[{\"role\":\"user\",\"content\":\"%s\"}]}",
+                                  "{\"model\":\"%s\",\"stream\":%s,\"input\":\"%s\"}",
                                   model_esc, req->stream ? "true" : "false", prompt_esc);
      }
 
diff --git a/src/bin/edi_agent_parse.c b/src/bin/edi_agent_parse.c
index 1752d97..cc77758 100644
--- a/src/bin/edi_agent_parse.c
+++ b/src/bin/edi_agent_parse.c
@@ -148,7 +148,24 @@ edi_agent_response_parse_for_provider(const char *provider, const char *json)
    if (provider && !strcmp(provider, "google_codex"))
      text = _edi_agent_json_first_string_value_get(json, "\"text\"");
    else
-     text = _edi_agent_json_first_string_value_get(json, "\"content\"");
+     {
+        text = _edi_agent_json_first_string_value_get(json, "\"delta\"");
+        if (!text || !text[0])
+          {
+             free(text);
+             text = _edi_agent_json_first_string_value_get(json, "\"output_text\"");
+          }
+        if (!text || !text[0])
+          {
+             free(text);
+             text = _edi_agent_json_first_string_value_get(json, "\"text\"");
+          }
+        if (!text || !text[0])
+          {
+             free(text);
+             text = _edi_agent_json_first_string_value_get(json, "\"content\"");
+          }
+     }
 
    if (text && text[0])
      return text;
diff --git a/src/bin/edi_aipanel.c b/src/bin/edi_aipanel.c
index 2e6a553..c680000 100644
--- a/src/bin/edi_aipanel.c
+++ b/src/bin/edi_aipanel.c
@@ -229,7 +229,7 @@ _edi_aipanel_prompt_build_initial(const char *user_prompt)
 
 static char *
 _edi_aipanel_prompt_build_followup(const char *executed_cmd, int exit_code,
-                                   const char *output)
+                                   const char *output, const char *file_preview)
 {
    char *state;
    char *output_clip;
@@ -254,6 +254,8 @@ _edi_aipanel_prompt_build_followup(const char *executed_cmd, int exit_code,
    eina_strbuf_append_printf(buf, "Executed command:\n%s\n\n", executed_cmd ?: "");
    eina_strbuf_append_printf(buf, "Exit code: %d\n\n", exit_code);
    eina_strbuf_append_printf(buf, "Command output:\n%s\n\n", output_clip ?: "");
+   if (file_preview && file_preview[0])
+     eina_strbuf_append_printf(buf, "File result:\n%s\n\n", file_preview);
    eina_strbuf_append_printf(buf, "Updated state:\n%s\n", state ?: "");
 
    out = eina_strbuf_string_steal(buf);
@@ -450,6 +452,166 @@ _edi_aipanel_command_is_mutating(const char *cmd)
    return EINA_FALSE;
 }
 
+static char *
+_edi_aipanel_token_unquote(const char *token)
+{
+   size_t len;
+   char *out;
+
+   if (!token)
+     return NULL;
+
+   len = strlen(token);
+   if (len >= 2 &&
+       ((token[0] == '\'' && token[len - 1] == '\'') ||
+        (token[0] == '"' && token[len - 1] == '"')))
+     return strndup(token + 1, len - 2);
+
+   out = strdup(token);
+   return out;
+}
+
+static char *
+_edi_aipanel_last_token_get(const char *cmd)
+{
+   const char *p;
+   const char *start;
+   char *raw;
+   char *out;
+
+   if (!cmd || !cmd[0])
+     return NULL;
+
+   p = cmd + strlen(cmd);
+   while (p > cmd && isspace((unsigned char)*(p - 1)))
+     p--;
+   if (p == cmd)
+     return NULL;
+
+   start = p;
+   while (start > cmd && !isspace((unsigned char)*(start - 1)))
+     start--;
+
+   raw = strndup(start, p - start);
+   out = _edi_aipanel_token_unquote(raw);
+   free(raw);
+   return out;
+}
+
+static char *
+_edi_aipanel_redirection_target_guess(const char *cmd)
+{
+   const char *p;
+   const char *t;
+   char *raw;
+   char *out;
+
+   if (!cmd || !cmd[0])
+     return NULL;
+
+   p = strrchr(cmd, '>');
+   if (!p)
+     return NULL;
+
+   t = p + 1;
+   if (*t == '>')
+     t++;
+   while (*t && isspace((unsigned char)*t))
+     t++;
+   if (!*t)
+     return NULL;
+
+   p = t;
+   while (*p && !isspace((unsigned char)*p) && *p != ';' && *p != '|' && *p != '&')
+     p++;
+   if (p == t)
+     return NULL;
+
+   raw = strndup(t, p - t);
+   out = _edi_aipanel_token_unquote(raw);
+   free(raw);
+   if (!out || !out[0] || out[0] == '-')
+     {
+        free(out);
+        return NULL;
+     }
+
+   return out;
+}
+
+static char *
+_edi_aipanel_created_path_guess(const char *cmd)
+{
+   char token[64];
+   char *last;
+
+   if (!_edi_aipanel_command_token_get(cmd, token, sizeof(token)))
+     return NULL;
+
+   if (!strcmp(token, "touch") || !strcmp(token, "cp") ||
+       !strcmp(token, "mv") || !strcmp(token, "tee"))
+     {
+        last = _edi_aipanel_last_token_get(cmd);
+        if (!last || !last[0] || last[0] == '-' || strchr(last, '|') || strchr(last, ';'))
+          {
+             free(last);
+             return NULL;
+          }
+        return last;
+     }
+
+   if (strstr(cmd, ">"))
+     return _edi_aipanel_redirection_target_guess(cmd);
+
+   return NULL;
+}
+
+static char *
+_edi_aipanel_created_file_preview_get(const char *cmd)
+{
+   char *path;
+   char *project_quoted;
+   char *path_quoted;
+   const char *script;
+   char *script_quoted;
+   const char *full_cmd;
+   char *out;
+   char *clip;
+
+   path = _edi_aipanel_created_path_guess(cmd);
+   if (!path)
+     return NULL;
+
+   project_quoted = _edi_aipanel_shell_quote(edi_project_get() ?: ".");
+   path_quoted = _edi_aipanel_shell_quote(path);
+   script = eina_slstr_printf(
+      "cd %s && if [ -f %s ]; then "
+      "printf 'status: file_exists\\npath: %s\\nsize_bytes: '; wc -c < %s; "
+      "printf 'preview:\\n'; sed -n '1,120p' %s; "
+      "elif [ -e %s ]; then "
+      "printf 'status: exists_not_file\\npath: %s\\n'; "
+      "else "
+      "printf 'status: missing\\npath: %s\\n'; "
+      "fi",
+      project_quoted, path_quoted, path_quoted, path_quoted, path_quoted,
+      path_quoted, path_quoted, path_quoted);
+   script_quoted = _edi_aipanel_shell_quote(script);
+   full_cmd = eina_slstr_printf("/bin/sh -lc %s", script_quoted);
+   out = edi_exe_response(full_cmd);
+
+   free(script_quoted);
+   free(path_quoted);
+   free(project_quoted);
+   free(path);
+
+   if (!out)
+     return strdup("status: unknown\nreason: preview command failed");
+
+   clip = _edi_aipanel_text_clip(out, 8000);
+   free(out);
+   return clip;
+}
+
 static void
 _edi_aipanel_inspection_state_update(const char *cmd, int exit_code)
 {
@@ -678,6 +840,33 @@ _edi_aipanel_append_line(const char *line)
    _edi_aipanel_follow_tail();
 }
 
+static void
+_edi_aipanel_append_multiline(const char *text)
+{
+   const char *start;
+   const char *end;
+
+   if (!text || !text[0])
+     return;
+
+   start = text;
+   while (start)
+     {
+        end = strchr(start, '\n');
+        if (end)
+          {
+             _edi_aipanel_append_line(eina_slstr_printf("%.*s", (int)(end - start), start));
+             start = end + 1;
+          }
+        else
+          {
+             if (*start)
+               _edi_aipanel_append_line(start);
+             break;
+          }
+     }
+}
+
 static void
 _edi_aipanel_send_state_set(Eina_Bool busy)
 {
@@ -721,11 +910,12 @@ _edi_aipanel_response_cb(const char *response, const char *error, void *data EIN
                   : NULL;
         if (run_cmd && _edi_ai_agent_steps < _edi_aipanel_steps_max_get())
           {
-             const char *deny_reason = NULL;
-             char *output;
-             char *followup_prompt;
-             int exit_code;
-             Eina_Bool allowed;
+	             const char *deny_reason = NULL;
+	             char *output;
+	             char *file_preview;
+	             char *followup_prompt;
+	             int exit_code;
+	             Eina_Bool allowed;
 
              allowed = _edi_aipanel_command_allowed(run_cmd, &deny_reason);
              if (!allowed)
@@ -779,21 +969,30 @@ _edi_aipanel_response_cb(const char *response, const char *error, void *data EIN
                     }
                   else
                     {
-                  _edi_ai_agent_steps++;
-                  output = _edi_aipanel_command_run(run_cmd, &exit_code);
-                  free(_edi_ai_last_stage_cmd);
-                  _edi_ai_last_stage_cmd = strdup(run_cmd ?: "");
-                  free(_edi_ai_last_stage_output);
-                  _edi_ai_last_stage_output = strdup(output ?: "");
+	                  _edi_ai_agent_steps++;
+	                  output = _edi_aipanel_command_run(run_cmd, &exit_code);
+	                  file_preview = _edi_aipanel_created_file_preview_get(run_cmd);
+	                  free(_edi_ai_last_stage_cmd);
+	                  _edi_ai_last_stage_cmd = strdup(run_cmd ?: "");
+	                  free(_edi_ai_last_stage_output);
+	                  _edi_ai_last_stage_output = strdup(output ?: "");
                   _edi_ai_last_stage_exit_code = exit_code;
                   _edi_ai_last_stage_index = _edi_ai_agent_steps;
                   _edi_ai_last_stage_valid = EINA_TRUE;
-                  if (inspect_cmd)
-                    _edi_aipanel_inspection_state_update(run_cmd, exit_code);
+	                  if (inspect_cmd)
+	                    _edi_aipanel_inspection_state_update(run_cmd, exit_code);
 
-                  followup_prompt = _edi_aipanel_prompt_build_followup(run_cmd, exit_code, output ?: "");
-                  free(output);
-                  _edi_ai_request = edi_agent_request_send(followup_prompt, _edi_aipanel_response_cb, NULL);
+	                  if (file_preview && file_preview[0])
+	                    {
+	                       _edi_aipanel_append_line("[run] File result:");
+	                       _edi_aipanel_append_multiline(file_preview);
+	                    }
+	                  followup_prompt = _edi_aipanel_prompt_build_followup(run_cmd, exit_code,
+	                                                                       output ?: "",
+	                                                                       file_preview ?: "");
+	                  free(output);
+	                  free(file_preview);
+	                  _edi_ai_request = edi_agent_request_send(followup_prompt, _edi_aipanel_response_cb, NULL);
                   free(followup_prompt);
                   free(run_cmd);
                   run_cmd = NULL;
diff --git a/src/tests/edi_test_agent_parse.c b/src/tests/edi_test_agent_parse.c
index 3c0d9e5..0c54c47 100644
--- a/src/tests/edi_test_agent_parse.c
+++ b/src/tests/edi_test_agent_parse.c
@@ -35,6 +35,34 @@ START_TEST(edi_test_agent_parse_openai_response)
 }
 END_TEST
 
+START_TEST(edi_test_agent_parse_openai_responses_output_text)
+{
+   char *parsed;
+
+   parsed = edi_agent_response_parse_for_provider(
+      "openai_compatible",
+      "{\"output\":[{\"content\":[{\"type\":\"output_text\",\"text\":\"refactor done\"}]}]}");
+
+   ck_assert_ptr_nonnull(parsed);
+   ck_assert_str_eq(parsed, "refactor done");
+   free(parsed);
+}
+END_TEST
+
+START_TEST(edi_test_agent_parse_openai_responses_delta)
+{
+   char *parsed;
+
+   parsed = edi_agent_response_parse_for_provider(
+      "openai_compatible",
+      "{\"type\":\"response.output_text.delta\",\"delta\":\"abc\"}");
+
+   ck_assert_ptr_nonnull(parsed);
+   ck_assert_str_eq(parsed, "abc");
+   free(parsed);
+}
+END_TEST
+
 START_TEST(edi_test_agent_parse_error_message)
 {
    char *parsed;
@@ -60,7 +88,7 @@ START_TEST(edi_test_agent_validate_rules)
    cfg.agent.enabled = EINA_TRUE;
 
    err = edi_agent_provider_validate_for_provider(&cfg, "openai_compatible",
-                                                  "https://api.example.com/v1/chat/completions",
+                                                  "https://api.example.com/v1/responses",
                                                   "gpt-test");
    ck_assert_ptr_nonnull(err);
    ck_assert_str_eq(err, "API key is required for this provider.");
@@ -68,13 +96,13 @@ START_TEST(edi_test_agent_validate_rules)
 
    cfg.agent.api_key = "token";
    err = edi_agent_provider_validate_for_provider(&cfg, "openai_compatible",
-                                                  "https://api.example.com/v1/chat/completions",
+                                                  "https://api.example.com/v1/responses",
                                                   "gpt-test");
    ck_assert_ptr_null(err);
 
    cfg.agent.api_key = "";
    err = edi_agent_provider_validate_for_provider(&cfg, "local_http",
-                                                  "http://127.0.0.1:11434/v1/chat/completions",
+                                                  "http://127.0.0.1:11434/v1/responses",
                                                   "qwen2.5");
    ck_assert_ptr_null(err);
 }
@@ -85,6 +113,8 @@ edi_test_agent_parse(TCase *tc)
 {
    tcase_add_test(tc, edi_test_agent_parse_google_response);
    tcase_add_test(tc, edi_test_agent_parse_openai_response);
+   tcase_add_test(tc, edi_test_agent_parse_openai_responses_output_text);
+   tcase_add_test(tc, edi_test_agent_parse_openai_responses_delta);
    tcase_add_test(tc, edi_test_agent_parse_error_message);
    tcase_add_test(tc, edi_test_agent_validate_rules);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to