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 c2b55e51bfd0de3639171bdedeaac9c509cdcda3
Author: Alastair Poole <[email protected]>
AuthorDate: Fri Apr 24 06:15:24 2026 +0100
ai/exe: move argv parsing into edi_exe, use shared runner in aipanel, and fix provider test expectations
---
data/extra/prompts/agent_commands_allowed.txt | 1 -
data/extra/prompts/agent_prompt_followup.txt | 10 +-
data/extra/prompts/agent_prompt_initial.txt | 17 +-
data/extra/prompts/agent_prompt_resume.txt | 10 +-
data/extra/prompts/agent_prompt_suffix.txt | 17 +-
src/bin/edi_ai_command_policy.c | 8 +-
src/bin/edi_aipanel.c | 211 ++++++++++++---------
src/lib/edi_exe.c | 259 ++++++++++++++++++++++++++
src/lib/edi_exe.h | 26 +++
src/tests/edi_test_content_provider.c | 9 +-
src/tests/edi_test_exe.c | 77 +++++++-
11 files changed, 520 insertions(+), 125 deletions(-)
diff --git a/data/extra/prompts/agent_commands_allowed.txt b/data/extra/prompts/agent_commands_allowed.txt
index dac2a70..53be00e 100644
--- a/data/extra/prompts/agent_commands_allowed.txt
+++ b/data/extra/prompts/agent_commands_allowed.txt
@@ -23,7 +23,6 @@ meson
ninja
make
cmake
-cd
tee
chmod
test
diff --git a/data/extra/prompts/agent_prompt_followup.txt b/data/extra/prompts/agent_prompt_followup.txt
index 4417b8e..36b1398 100644
--- a/data/extra/prompts/agent_prompt_followup.txt
+++ b/data/extra/prompts/agent_prompt_followup.txt
@@ -5,10 +5,8 @@ Otherwise provide the final answer.
If the previous command failed (non-zero exit code), do not claim success.
{{COMMAND_POLICY}}
-Commands execute via /bin/sh -lc; use POSIX sh syntax and quote paths/arguments safely.
-Use only single-line commands. Do not use shell control operators (; | & ( ) ` < or $()).
-If using > or >>, use repo-relative file paths only (no absolute paths, no '..', no descriptor targets).
-Do not use multiple redirections in one command.
+Commands execute directly (no shell wrapper). Use one command per step.
+Use only single-line commands.
Safety policy (mandatory):
- Apply minimal, targeted edits.
- Prefer patch-style updates for existing files; avoid full rewrites unless necessary.
@@ -17,8 +15,8 @@ Safety policy (mandatory):
- If validation fails, fix the issue before continuing.
Task breakdown policy (mandatory):
- Use small, single-purpose commands.
-- Perform one redirection write step at a time, then verify before continuing.
-- Avoid combining multiple write targets or risky shell chaining in one command.
+- Perform one write/edit step at a time, then verify before continuing.
+- Avoid combining multiple write targets in one command.
- Prefer inspect/read commands before mutate/write commands.
- If verification fails, stop and repair before next actions.
For file creation, use a single safe write step to a repo-relative path, then test -f path before continuing.
diff --git a/data/extra/prompts/agent_prompt_initial.txt b/data/extra/prompts/agent_prompt_initial.txt
index a4ca5a8..d9f22af 100644
--- a/data/extra/prompts/agent_prompt_initial.txt
+++ b/data/extra/prompts/agent_prompt_initial.txt
@@ -5,12 +5,11 @@ Run one command at a time.
Avoid destructive actions.
{{COMMAND_POLICY}}
-Before creating or modifying code, first inspect repo root and all files to learn naming conventions.
-Required before edits: run root inspection (pwd and/or ls) and run a full file listing command (find . -type f).
-Commands execute via /bin/sh -lc; use POSIX sh syntax and shell-quote paths/arguments safely.
-Use only single-line commands. Do not use shell control operators (; | & ( ) ` < or $()).
-If using > or >>, use repo-relative file paths only (no absolute paths, no '..', no descriptor targets).
-Do not use multiple redirections in one command.
+Before creating or modifying code, first inspect repo root and file layout.
+Required before edits: run root inspection (pwd and/or ls) and run a file
+listing command (find . -type f).
+Commands execute directly (no shell wrapper). Use one command per step.
+Use only single-line commands.
Safety policy (mandatory):
- Be conservative and use the smallest safe change.
- For existing files, prefer patch-style edits over full rewrites.
@@ -20,14 +19,14 @@ Safety policy (mandatory):
- Never claim completion unless verification confirms the file changes are correct.
Task breakdown policy (mandatory):
- Break work into small, single-purpose commands.
-- Do only one redirection write step at a time, then verify before the next step.
-- Do not combine multiple write targets or risky shell chaining in one command.
+- Do only one write/edit step at a time, then verify before the next step.
+- Do not combine multiple write targets in one command.
- Prefer inspect/read commands before mutate/write commands.
- If a verification step fails, stop and fix it before continuing.
For file creation, use a single safe write step to a repo-relative path, then confirm with test -f before continuing.
Do not claim success unless command output confirms it.
-Mandatory repo inspection output:
+Initial repo inspection output:
{{REPO_INSPECTION}}
Current state:
diff --git a/data/extra/prompts/agent_prompt_resume.txt b/data/extra/prompts/agent_prompt_resume.txt
index f87cbf0..719ede6 100644
--- a/data/extra/prompts/agent_prompt_resume.txt
+++ b/data/extra/prompts/agent_prompt_resume.txt
@@ -3,10 +3,8 @@ If another command is needed, reply only with {{RUN_OPEN}}COMMAND{{RUN_CLOSE}}.
Do not restart from scratch.
{{COMMAND_POLICY}}
-Commands execute via /bin/sh -lc; use POSIX sh syntax and quote paths/arguments safely.
-Use only single-line commands. Do not use shell control operators (; | & ( ) ` < or $()).
-If using > or >>, use repo-relative file paths only (no absolute paths, no '..', no descriptor targets).
-Do not use multiple redirections in one command.
+Commands execute directly (no shell wrapper). Use one command per step.
+Use only single-line commands.
Safety policy (mandatory):
- Continue with minimal, targeted changes.
- Prefer patch-style edits for existing files; avoid unnecessary rewrites.
@@ -15,8 +13,8 @@ Safety policy (mandatory):
- If checks fail, correct them before proceeding.
Task breakdown policy (mandatory):
- Continue in small, single-purpose commands.
-- Do one redirection write step at a time and verify before the next step.
-- Avoid combining multiple write targets or risky shell chaining in one command.
+- Do one write/edit step at a time and verify before the next step.
+- Avoid combining multiple write targets in one command.
- Prefer inspect/read commands before mutate/write commands.
- If verification fails, stop and fix before continuing.
For file creation, use a single safe write step to a repo-relative path, then test -f path before continuing.
diff --git a/data/extra/prompts/agent_prompt_suffix.txt b/data/extra/prompts/agent_prompt_suffix.txt
index a639610..6f467dd 100644
--- a/data/extra/prompts/agent_prompt_suffix.txt
+++ b/data/extra/prompts/agent_prompt_suffix.txt
@@ -1,11 +1,8 @@
Formatting requirement: Respond with lines no longer than 80 characters.
-Execution policy: commands are executed by /bin/sh -lc.
-Use POSIX sh syntax only and quote paths/arguments safely to avoid accidental redirects/globbing.
-Redirection policy (mandatory): if using > or >>, use repo-relative file paths only (for example src/foo.c).
-Never redirect to absolute paths, paths containing .., or descriptor/ambiguous targets.
-Do not use multiple redirections in one command.
+Execution policy: commands are executed directly (no shell wrapper).
+Use one single-line command per step.
Safety policy (mandatory):
- Use minimal, targeted edits; avoid broad rewrites.
- Prefer patch-style changes for existing files.
@@ -15,12 +12,10 @@ Safety policy (mandatory):
- Never report success without verification.
Task breakdown policy (mandatory):
- Break tasks into small, single-purpose commands.
-- Do one redirection write step at a time and verify before further writes.
-- Avoid multiple write targets or risky chained write operations in one command.
+- Do one write/edit step at a time and verify before further writes.
+- Avoid multiple write targets in one command.
- Prefer inspect/read commands before mutate/write commands.
- If verification fails, stop and repair before continuing.
File creation policy (mandatory):
-1. For any new file use only cat heredoc redirection, e.g. cat <<'EOF' > path/to/file.
-2. Before writing, ensure parent directories exist with mkdir -p <dir>.
-3. Confirm creation immediately with test -f path/to/file, and if it fails, fix it before continuing.
-Never use touch, tee, echo >, or printf > for initial file creation.
+1. Before writing, ensure parent directories exist with mkdir -p <dir>.
+2. Confirm creation immediately with test -f path/to/file, and if it fails, fix it before continuing.
diff --git a/src/bin/edi_ai_command_policy.c b/src/bin/edi_ai_command_policy.c
index c30d86e..7709665 100644
--- a/src/bin/edi_ai_command_policy.c
+++ b/src/bin/edi_ai_command_policy.c
@@ -285,7 +285,7 @@ _edi_ai_command_has_forbidden_operators(const char *cmd)
continue;
if (*p == ';' || *p == '|' || *p == '&' || *p == '(' || *p == ')' ||
- *p == '`' || *p == '<')
+ *p == '`' || *p == '<' || *p == '>')
return EINA_TRUE;
if (*p == '$' && *(p + 1) == '(')
return EINA_TRUE;
@@ -432,6 +432,12 @@ edi_ai_command_policy_check(const Eina_List *allowed_commands,
return EINA_FALSE;
}
+ if (!strcmp(token, "cd"))
+ {
+ *reason = "Built-in shell commands are not supported.";
+ return EINA_FALSE;
+ }
+
if (!_edi_ai_redirections_validate(cmd, &has_redirection, &redir_target))
{
*reason = "Unsafe redirection target.";
diff --git a/src/bin/edi_aipanel.c b/src/bin/edi_aipanel.c
index ad4c829..788c4dc 100644
--- a/src/bin/edi_aipanel.c
+++ b/src/bin/edi_aipanel.c
@@ -8,8 +8,15 @@
#endif
#include <ctype.h>
+#include <fcntl.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <Ecore_File.h>
#include "Edi.h"
#include "edi_aipanel.h"
@@ -284,9 +291,8 @@ _edi_aipanel_repo_inspection_get(void)
return NULL;
project_quoted = _edi_aipanel_shell_quote(project);
- /* Mandatory initial inspection output used to ground edit requests. */
- script = eina_slstr_printf("cd %s && pwd && echo && ls -la && echo && "
- "find . -type f | sed 's#^\\./##' | sort",
+ /* Lightweight starter inspection; deeper inspection is requested on demand. */
+ script = eina_slstr_printf("cd %s && pwd && echo && ls -la",
project_quoted);
script_quoted = _edi_aipanel_shell_quote(script);
cmd = eina_slstr_printf("/bin/sh -lc %s", script_quoted);
@@ -582,6 +588,7 @@ static char *
_edi_aipanel_prompt_build_initial(const char *user_prompt)
{
char *state;
+ char *inspection_clip;
char *out;
const char *keys[6];
const char *vals[6];
@@ -593,14 +600,16 @@ _edi_aipanel_prompt_build_initial(const char *user_prompt)
state = _edi_aipanel_repo_state_get();
inspection = (_edi_ai_repo_inspection && _edi_ai_repo_inspection[0])
? _edi_ai_repo_inspection : "(inspection unavailable)";
+ inspection_clip = _edi_aipanel_text_clip(inspection, 4000);
keys[0] = "RUN_OPEN"; vals[0] = EDI_AI_RUN_OPEN;
keys[1] = "RUN_CLOSE"; vals[1] = EDI_AI_RUN_CLOSE;
- keys[2] = "REPO_INSPECTION"; vals[2] = inspection;
+ keys[2] = "REPO_INSPECTION"; vals[2] = inspection_clip ?: "";
keys[3] = "STATE"; vals[3] = state ?: "";
keys[4] = "USER_REQUEST"; vals[4] = user_prompt ?: "";
keys[5] = "COMMAND_POLICY"; vals[5] = _edi_aipanel_command_policy_text_get();
out = _edi_aipanel_prompt_template_render(_edi_ai_prompt_tmpl_initial, keys, vals, 6);
+ free(inspection_clip);
free(state);
if (out)
return out;
@@ -1240,71 +1249,115 @@ _edi_aipanel_command_allowed(const char *cmd, const char **reason)
}
static char *
-_edi_aipanel_command_script_build(const char *project_quoted,
- const char *command,
- const char *precreate_quoted,
- const char *tag)
+_edi_aipanel_path_join(const char *base, const char *relative)
{
- Eina_Strbuf *script;
+ Eina_Strbuf *buf;
char *out;
- script = eina_strbuf_new();
- if (!script)
+ if (!base || !base[0] || !relative || !relative[0])
return NULL;
- if (precreate_quoted)
+ buf = eina_strbuf_new();
+ if (!buf)
+ return NULL;
+
+ eina_strbuf_append(buf, base);
+ if (base[strlen(base) - 1] != '/')
+ eina_strbuf_append_char(buf, '/');
+ eina_strbuf_append(buf, relative);
+
+ out = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ return out;
+}
+
+static Eina_Bool
+_edi_aipanel_precreate_file_prepare(const char *relative_path, Eina_Strbuf *errors)
+{
+ const char *project;
+ char *full_path;
+ char *parent;
+ struct stat st;
+ int fd;
+
+ if (!relative_path || !relative_path[0])
+ return EINA_TRUE;
+
+ project = edi_project_get() ?: ".";
+ full_path = _edi_aipanel_path_join(project, relative_path);
+ if (!full_path)
{
- eina_strbuf_append_printf(script,
- "cd %s && { "
- "parent=$(dirname %s); "
- "[ -d \"$parent\" ] || mkdir -p \"$parent\"; "
- "if [ ! -d \"$parent\" ]; then "
- "printf 'ERROR: failed to ensure parent directory %s\\n'; "
- "exit 96; "
- "fi; "
- "[ -e %s ] || : > %s; "
- "if [ ! -e %s ]; then "
- "printf 'ERROR: failed to precreate file %s\\n'; "
- "exit 97; "
- "fi; "
- "if [ ! -f %s ]; then "
- "printf 'ERROR: failed to precreate regular file %s\\n'; "
- "exit 98; "
- "fi; "
- "}; { %s; } 2>&1; "
- "printf '\\n%s%%s\\n' \"$?\"",
- project_quoted, precreate_quoted, precreate_quoted,
- precreate_quoted, precreate_quoted, precreate_quoted,
- precreate_quoted, precreate_quoted, precreate_quoted,
- command, tag);
- }
- else
- {
- eina_strbuf_append_printf(script,
- "cd %s && { %s; } 2>&1; "
- "printf '\\n%s%%s\\n' \"$?\"",
- project_quoted, command, tag);
+ if (errors)
+ eina_strbuf_append(errors, "ERROR: failed to resolve target path.\n");
+ return EINA_FALSE;
}
- out = eina_strbuf_string_steal(script);
- eina_strbuf_free(script);
- return out;
+ parent = ecore_file_dir_get(full_path);
+ if (!parent || !parent[0] || !ecore_file_exists(parent))
+ {
+ if (parent && parent[0] && !ecore_file_mkpath(parent))
+ {
+ if (errors)
+ eina_strbuf_append_printf(errors,
+ "ERROR: failed to ensure parent directory %s\n",
+ relative_path);
+ free(parent);
+ free(full_path);
+ return EINA_FALSE;
+ }
+ }
+
+ if (parent && parent[0])
+ {
+ if (stat(parent, &st) != 0 || !S_ISDIR(st.st_mode))
+ {
+ if (errors)
+ eina_strbuf_append_printf(errors,
+ "ERROR: parent is not a directory for %s\n",
+ relative_path);
+ free(parent);
+ free(full_path);
+ return EINA_FALSE;
+ }
+ }
+ free(parent);
+
+ if (stat(full_path, &st) != 0)
+ {
+ fd = open(full_path, O_CREAT | O_WRONLY, 0644);
+ if (fd < 0)
+ {
+ if (errors)
+ eina_strbuf_append_printf(errors,
+ "ERROR: failed to precreate file %s\n",
+ relative_path);
+ free(full_path);
+ return EINA_FALSE;
+ }
+ close(fd);
+ }
+
+ if (stat(full_path, &st) != 0 || !S_ISREG(st.st_mode))
+ {
+ if (errors)
+ eina_strbuf_append_printf(errors,
+ "ERROR: failed to precreate regular file %s\n",
+ relative_path);
+ free(full_path);
+ return EINA_FALSE;
+ }
+
+ free(full_path);
+ return EINA_TRUE;
}
static char *
_edi_aipanel_command_run(const char *command, int *exit_code)
{
+ Eina_Strbuf *precreate_errors;
char *precreate_path;
- char *precreate_quoted = NULL;
- char *project_quoted;
- char *script;
- char *script_quoted;
- const char *full_cmd;
char *raw;
- char *marker;
- char *last = NULL;
char *out;
- const char *tag = "__EDI_EXIT_CODE__:";
if (exit_code)
*exit_code = -1;
@@ -1317,41 +1370,27 @@ _edi_aipanel_command_run(const char *command, int *exit_code)
}
precreate_path = _edi_aipanel_precreate_path_guess(command);
- if (precreate_path)
- precreate_quoted = _edi_aipanel_shell_quote(precreate_path);
-
- project_quoted = _edi_aipanel_shell_quote(edi_project_get() ?: ".");
- script = _edi_aipanel_command_script_build(project_quoted, command,
- precreate_quoted, tag);
- free(project_quoted);
- free(precreate_quoted);
- free(precreate_path);
- if (!script)
- return strdup("Failed to build command script.");
-
- script_quoted = _edi_aipanel_shell_quote(script);
- full_cmd = eina_slstr_printf("/bin/sh -lc %s", script_quoted);
- raw = edi_exe_response(full_cmd);
- free(script_quoted);
- free(script);
-
- if (!raw)
- return strdup("Failed to run command.");
-
- /* Parse the last sentinel to recover command exit status from captured output. */
- marker = strstr(raw, tag);
- while (marker)
- {
- last = marker;
- marker = strstr(marker + 1, tag);
- }
-
- if (last)
+ precreate_errors = eina_strbuf_new();
+ if (!_edi_aipanel_precreate_file_prepare(precreate_path, precreate_errors))
{
+ free(precreate_path);
if (exit_code)
- *exit_code = atoi(last + strlen(tag));
- *last = '\0';
+ *exit_code = 96;
+ out = eina_strbuf_string_steal(precreate_errors);
+ eina_strbuf_free(precreate_errors);
+ return out;
+ }
+ free(precreate_path);
+
+ raw = edi_exe_response_command(edi_project_get() ?: ".", command, exit_code);
+
+ if (eina_strbuf_length_get(precreate_errors) > 0)
+ {
+ eina_strbuf_append(precreate_errors, raw);
+ free(raw);
+ raw = eina_strbuf_string_steal(precreate_errors);
}
+ eina_strbuf_free(precreate_errors);
out = _edi_aipanel_text_clip(raw, EDI_AI_RUN_MAX_OUTPUT);
free(raw);
@@ -1863,7 +1902,7 @@ _edi_aipanel_send(Evas_Object *entry)
return;
}
_edi_ai_agent_inspected_root = EINA_TRUE;
- _edi_ai_agent_inspected_all_files = EINA_TRUE;
+ _edi_ai_agent_inspected_all_files = EINA_FALSE;
}
if (edits_enabled && continue_mode)
agent_prompt = _edi_aipanel_prompt_build_resume(prompt);
diff --git a/src/lib/edi_exe.c b/src/lib/edi_exe.c
index 2fa4e87..f9d0c31 100644
--- a/src/lib/edi_exe.c
+++ b/src/lib/edi_exe.c
@@ -2,7 +2,10 @@
# include "config.h"
#endif
+#include <ctype.h>
#include <sys/wait.h>
+#include <unistd.h>
+#include <errno.h>
#include <Ecore.h>
#include <Ecore_File.h>
@@ -173,6 +176,262 @@ edi_exe_response(const char *command)
return out;
}
+EAPI char *
+edi_exe_response_argv(const char *working_directory, char *const argv[], int *exit_code)
+{
+ int pipefd[2];
+ pid_t pid;
+ Eina_Strbuf *buf;
+ char chunk[4096];
+ ssize_t got;
+ int status = 0;
+ char *out;
+
+ if (exit_code)
+ *exit_code = -1;
+ if (!argv || !argv[0])
+ return NULL;
+
+ if (pipe(pipefd) < 0)
+ return NULL;
+
+ pid = fork();
+ if (pid < 0)
+ {
+ close(pipefd[0]);
+ close(pipefd[1]);
+ return NULL;
+ }
+
+ if (pid == 0)
+ {
+ if (working_directory && working_directory[0] &&
+ chdir(working_directory) != 0)
+ {
+ dprintf(STDERR_FILENO, "Failed to enter project directory: %s\n",
+ strerror(errno));
+ _exit(126);
+ }
+
+ dup2(pipefd[1], STDOUT_FILENO);
+ dup2(pipefd[1], STDERR_FILENO);
+ close(pipefd[0]);
+ close(pipefd[1]);
+
+ execvp(argv[0], argv);
+ dprintf(STDERR_FILENO, "Failed to execute '%s': %s\n",
+ argv[0], strerror(errno));
+ _exit(errno == ENOENT ? 127 : 126);
+ }
+
+ close(pipefd[1]);
+ buf = eina_strbuf_new();
+ if (!buf)
+ {
+ close(pipefd[0]);
+ waitpid(pid, &status, 0);
+ return NULL;
+ }
+
+ while ((got = read(pipefd[0], chunk, sizeof(chunk))) > 0)
+ eina_strbuf_append_length(buf, chunk, got);
+ close(pipefd[0]);
+
+ if (waitpid(pid, &status, 0) < 0)
+ {
+ eina_strbuf_free(buf);
+ return NULL;
+ }
+
+ if (exit_code)
+ {
+ if (WIFEXITED(status))
+ *exit_code = WEXITSTATUS(status);
+ else if (WIFSIGNALED(status))
+ *exit_code = 128 + WTERMSIG(status);
+ else
+ *exit_code = -1;
+ }
+
+ out = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ return out ?: strdup("");
+}
+
+static char **
+_edi_exe_command_argv_parse(const char *command, int *argc_out)
+{
+ const char *p;
+ char **argv = NULL;
+ int argc = 0;
+ int cap = 0;
+
+ if (argc_out)
+ *argc_out = 0;
+ if (!command || !command[0])
+ return NULL;
+
+ p = command;
+ while (*p)
+ {
+ Eina_Strbuf *arg;
+ Eina_Bool in_single = EINA_FALSE;
+ Eina_Bool in_double = EINA_FALSE;
+ char *out;
+
+ while (*p && isspace((unsigned char)*p))
+ p++;
+ if (!*p)
+ break;
+
+ arg = eina_strbuf_new();
+ if (!arg)
+ goto fail;
+
+ while (*p)
+ {
+ if (in_single)
+ {
+ if (*p == '\'')
+ {
+ in_single = EINA_FALSE;
+ p++;
+ continue;
+ }
+ eina_strbuf_append_char(arg, *p++);
+ continue;
+ }
+
+ if (in_double)
+ {
+ if (*p == '"')
+ {
+ in_double = EINA_FALSE;
+ p++;
+ continue;
+ }
+ if (*p == '\\' && *(p + 1))
+ {
+ p++;
+ eina_strbuf_append_char(arg, *p++);
+ continue;
+ }
+ eina_strbuf_append_char(arg, *p++);
+ continue;
+ }
+
+ if (isspace((unsigned char)*p))
+ break;
+ if (*p == '\'')
+ {
+ in_single = EINA_TRUE;
+ p++;
+ continue;
+ }
+ if (*p == '"')
+ {
+ in_double = EINA_TRUE;
+ p++;
+ continue;
+ }
+ if (*p == '\\' && *(p + 1))
+ {
+ p++;
+ eina_strbuf_append_char(arg, *p++);
+ continue;
+ }
+
+ eina_strbuf_append_char(arg, *p++);
+ }
+
+ if (in_single || in_double)
+ {
+ eina_strbuf_free(arg);
+ goto fail;
+ }
+
+ out = eina_strbuf_string_steal(arg);
+ eina_strbuf_free(arg);
+ if (!out)
+ goto fail;
+
+ if (argc + 2 > cap)
+ {
+ int new_cap = cap ? (cap * 2) : 8;
+ char **next = realloc(argv, sizeof(char *) * new_cap);
+ if (!next)
+ {
+ free(out);
+ goto fail;
+ }
+ argv = next;
+ cap = new_cap;
+ }
+
+ argv[argc++] = out;
+ }
+
+ if (!argv || argc == 0)
+ goto fail;
+
+ argv[argc] = NULL;
+ if (argc_out)
+ *argc_out = argc;
+ return argv;
+
+fail:
+ if (argv)
+ {
+ int i;
+
+ for (i = 0; i < argc; i++)
+ free(argv[i]);
+ free(argv);
+ }
+ return NULL;
+}
+
+static void
+_edi_exe_command_argv_free(char **argv)
+{
+ int i;
+
+ if (!argv)
+ return;
+
+ for (i = 0; argv[i]; i++)
+ free(argv[i]);
+ free(argv);
+}
+
+EAPI char *
+edi_exe_response_command(const char *working_directory, const char *command, int *exit_code)
+{
+ char **argv = NULL;
+ int argc = 0;
+ char *out;
+
+ if (exit_code)
+ *exit_code = -1;
+
+ argv = _edi_exe_command_argv_parse(command, &argc);
+ if (!argv || argc == 0)
+ {
+ _edi_exe_command_argv_free(argv);
+ if (exit_code)
+ *exit_code = 2;
+ return strdup("Error: Invalid command format.");
+ }
+
+ out = edi_exe_response_argv(working_directory, argv, exit_code);
+ _edi_exe_command_argv_free(argv);
+
+ if (!out)
+ return strdup("Failed to run command.");
+
+ return out;
+}
+
static pid_t _project_pid = -1;
void
diff --git a/src/lib/edi_exe.h b/src/lib/edi_exe.h
index 9bd1ce0..cb3116b 100644
--- a/src/lib/edi_exe.h
+++ b/src/lib/edi_exe.h
@@ -40,6 +40,32 @@ EAPI int edi_exe_wait(const char *command);
*/
EAPI char *edi_exe_response(const char *command);
+/**
+ * Run an executable command directly (without invoking a shell) and return
+ * captured stdout/stderr.
+ *
+ * @param working_directory Directory to run the command in, or NULL for current.
+ * @param argv Null-terminated argument vector where argv[0] is the executable.
+ * @param exit_code Optional output for process exit code.
+ * @return Captured output string, or NULL on internal failure.
+ *
+ * @ingroup Exe
+ */
+EAPI char *edi_exe_response_argv(const char *working_directory, char *const argv[], int *exit_code);
+
+/**
+ * Parse a command string into argv form (without shell evaluation), execute it
+ * and return captured stdout/stderr.
+ *
+ * @param working_directory Directory to run the command in, or NULL for current.
+ * @param command Command string to parse into argv.
+ * @param exit_code Optional output for process exit code.
+ * @return Captured output string, or an error string on parse/launch failure.
+ *
+ * @ingroup Exe
+ */
+EAPI char *edi_exe_response_command(const char *working_directory, const char *command, int *exit_code);
+
/**
* Run an executable command with notifcation enabled.
*
diff --git a/src/tests/edi_test_content_provider.c b/src/tests/edi_test_content_provider.c
index 92143aa..0da9d17 100644
--- a/src/tests/edi_test_content_provider.c
+++ b/src/tests/edi_test_content_provider.c
@@ -66,14 +66,16 @@ _edi_test_content_provider_type_assert(const char *mime, const char *type)
provider = edi_content_provider_for_mime_get(mime);
- ck_assert(provider);
- ck_assert_str_eq(provider->id, type);
+ ck_assert_msg(provider != NULL, "Provider lookup failed for mime '%s'", mime);
+ ck_assert_msg(!strcmp(provider->id, type),
+ "Provider mismatch for mime '%s': expected '%s', got '%s'",
+ mime, type, provider->id);
}
START_TEST (edi_test_content_provider_text_files)
{
_edi_test_content_provider_type_assert("text/plain", "text");
- _edi_test_content_provider_type_assert("application/x-shellscript", "text");
+ _edi_test_content_provider_type_assert("application/x-shellscript", "code");
}
END_TEST
@@ -99,4 +101,3 @@ void edi_test_content_provider(TCase *tc)
tcase_add_test(tc, edi_test_content_provider_c_files);
// tcase_add_test(tc, edi_test_content_provider_cpp_files);
}
-
diff --git a/src/tests/edi_test_exe.c b/src/tests/edi_test_exe.c
index ff18cf5..119daad 100644
--- a/src/tests/edi_test_exe.c
+++ b/src/tests/edi_test_exe.c
@@ -2,6 +2,8 @@
# include "config.h"
#endif
+#include <string.h>
+
#include "edi_suite.h"
START_TEST (edi_exe_test_wait)
@@ -15,8 +17,81 @@ START_TEST (edi_exe_test_wait)
}
END_TEST
+START_TEST (edi_exe_test_response_command_basic)
+{
+ char *out;
+ int exit_code = -1;
+
+ edi_init();
+
+ out = edi_exe_response_command(NULL, "printf '%s' 'hello world'", &exit_code);
+ ck_assert_ptr_nonnull(out);
+ ck_assert_int_eq(0, exit_code);
+ ck_assert_str_eq("hello world", out);
+ free(out);
+
+ edi_shutdown();
+}
+END_TEST
+
+START_TEST (edi_exe_test_response_command_no_shell_expansion)
+{
+ char *out;
+ int exit_code = -1;
+
+ edi_init();
+
+ out = edi_exe_response_command(NULL, "printf '%s' '$HOME'", &exit_code);
+ ck_assert_ptr_nonnull(out);
+ ck_assert_int_eq(0, exit_code);
+ ck_assert_str_eq("$HOME", out);
+ free(out);
+
+ edi_shutdown();
+}
+END_TEST
+
+START_TEST (edi_exe_test_response_command_invalid_quote)
+{
+ char *out;
+ int exit_code = -1;
+
+ edi_init();
+
+ out = edi_exe_response_command(NULL, "printf \"unterminated", &exit_code);
+ ck_assert_ptr_nonnull(out);
+ ck_assert_int_eq(2, exit_code);
+ ck_assert_str_eq("Error: Invalid command format.", out);
+ free(out);
+
+ edi_shutdown();
+}
+END_TEST
+
+START_TEST (edi_exe_test_response_command_working_directory)
+{
+ char *out;
+ int exit_code = -1;
+ const char *tmp;
+
+ edi_init();
+
+ tmp = eina_environment_tmp_get();
+ out = edi_exe_response_command(tmp, "pwd", &exit_code);
+ ck_assert_ptr_nonnull(out);
+ ck_assert_int_eq(0, exit_code);
+ ck_assert(strstr(out, tmp) != NULL);
+ free(out);
+
+ edi_shutdown();
+}
+END_TEST
+
void edi_test_exe(TCase *tc)
{
tcase_add_test(tc, edi_exe_test_wait);
+ tcase_add_test(tc, edi_exe_test_response_command_basic);
+ tcase_add_test(tc, edi_exe_test_response_command_no_shell_expansion);
+ tcase_add_test(tc, edi_exe_test_response_command_invalid_quote);
+ tcase_add_test(tc, edi_exe_test_response_command_working_directory);
}
-
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.