forked from WHC/Hermit
Tools - Table-driven tool registry with permission classes and default/minimal profiles; new tools: edit_file, list_dir, glob, grep, delete_file, move_file, todo_write, web_fetch, ask_user (plus read_file paging). - Built-in Myers diff; write tools return unified diffs. - Persistent permission rules (.agent/permissions.json), per-turn undo snapshots (.agent/undo), AGENTS.md project notes, auto-compact at 80% of the model context, cancellable run_shell with process-group kill. TUI - Table-driven slash commands: /provider /key /effort /status /tools /permissions /yolo /undo /retry /diff /export /copy /rename /delete /init /max-steps /todo, with / and @ completion. - Permission modal with diff and prefix rules, ask_user modal, todo panel, header with model/effort/context, bracketed paste, line editing, wide-char cursor, NO_COLOR and ASCII fallback; Esc never quits. Startup and configuration - API keys are entered in the TUI (hidden) and saved per provider in <config>/credentials (0600); env variables are only a fallback. - Last provider, per-provider model and reasoning effort are remembered in <config>/settings.json; --effort/-e and /effort send reasoning_effort (low|medium|high|max) to models that accept it. - DeepSeek preset uses deepseek-flash / deepseek-v4-pro. - Session flags --new/--continue/--resume/--list-sessions, --yolo, --confirm. Compatibility and tests - ncurses detection, macOS/Homebrew support, make install, XDG config dir, POSIX cleanups; Gitea CI (gcc/clang/asan/musl/macOS). - Unit tests for diff, fs tools, registry, undo/perms and config; e2e fixtures multi_file_refactor and ask_or_todo; vendored cJSON.
79 lines
2.6 KiB
C
79 lines
2.6 KiB
C
#ifndef CST_OS_COMPAT_H
|
|
#define CST_OS_COMPAT_H
|
|
|
|
#include <stddef.h>
|
|
#include <time.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef OS_PATH_MAX
|
|
#define OS_PATH_MAX 4096
|
|
#endif
|
|
|
|
/* --- path --- */
|
|
int os_path_is_abs(const char *p);
|
|
/* Join with native separator; out always uses '/' on Unix and '\\' on Win for
|
|
* the joiner, but os_path_norm_slashes converts to '/' for comparisons. */
|
|
int os_path_join(char *out, size_t out_sz, const char *a, const char *b);
|
|
void os_path_norm_slashes(char *p);
|
|
int os_realpath(const char *path, char *out, size_t out_sz);
|
|
/* True if path is under root (after realpath/norm). Trailing slash rules apply. */
|
|
int os_path_under(const char *root, const char *path);
|
|
|
|
/* --- dirs / config --- */
|
|
int os_mkdir(const char *path, int mode);
|
|
int os_mkdir_p(const char *path, int mode);
|
|
int os_config_dir(char *out, size_t out_sz);
|
|
int os_temp_dir(char *out, size_t out_sz);
|
|
/* Create unique temp file; writes path into out; returns fd or -1. Caller closes. */
|
|
int os_mkstemp(char *out, size_t out_sz, const char *prefix);
|
|
|
|
/* Directory containing the running executable (for bundled busybox).
|
|
* Call os_set_prog_path(argv[0]) early on Unix/Termux as fallback. */
|
|
void os_set_prog_path(const char *argv0);
|
|
int os_exe_dir(char *out, size_t out_sz);
|
|
|
|
/* Resolve shell interpreter path into out.
|
|
* Order: CST_SHELL → <exe_dir>/busybox[.exe] → /bin/sh (Unix). */
|
|
int os_resolve_shell(char *out, size_t out_sz);
|
|
|
|
/* --- process --- */
|
|
typedef struct {
|
|
char *out;
|
|
size_t out_len;
|
|
int exit_code;
|
|
} os_run_result_t;
|
|
|
|
void os_run_result_free(os_run_result_t *r);
|
|
|
|
/* Run argv[0..] (NULL-terminated) with cwd; capture stdout+stderr.
|
|
* max_out caps captured bytes (0 = default 512KiB). */
|
|
int os_run_capture(const char *cwd, const char *const argv[], size_t max_out,
|
|
os_run_result_t *r);
|
|
|
|
/* Convenience: shell -c cmd via os_resolve_shell. */
|
|
int os_run_shell_c(const char *cwd, const char *cmd, size_t max_out,
|
|
os_run_result_t *r);
|
|
|
|
/* Child processes get stdin=/dev/null, their own process group, and are
|
|
* killed after the timeout (CST_SHELL_TIMEOUT seconds, default 120) or when
|
|
* *flag becomes non-zero. Exit code 124 = timeout, 130 = cancelled. */
|
|
void os_set_cancel_flag(volatile int *flag);
|
|
void os_set_run_timeout(int seconds);
|
|
|
|
/* Monotonic milliseconds (arbitrary epoch). */
|
|
double os_now_ms(void);
|
|
|
|
/* --- misc --- */
|
|
void os_localtime(const time_t *t, struct tm *out);
|
|
int os_getpid(void);
|
|
int os_chmod_private(const char *path); /* best-effort 0600; no-op/ok on Win */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* CST_OS_COMPAT_H */
|