Usability pass: tool registry, TUI polish, saved keys and settings

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.
This commit is contained in:
WHC
2026-10-05 01:47:01 +08:00
parent 9877ff48b6
commit 2fde898da0
105 changed files with 19348 additions and 3786 deletions
+27
View File
@@ -71,6 +71,31 @@ typedef struct {
typedef void (*ctl_on_event_fn)(const ctl_event_t *ev, void *userdata);
/* Why the stream left the contract (for protocol-adherence experiments). */
typedef enum {
CTL_EK_NONE = 0,
CTL_EK_BAD_CALL, /* malformed `call` line */
CTL_EK_BAD_ARG, /* malformed `arg` header / bad heredoc tag */
CTL_EK_UNEXPECTED_LINE, /* non arg/end line inside a call (nbytes too small) */
CTL_EK_BODY_EOF, /* EOF inside a length-prefixed body (nbytes too big) */
CTL_EK_HEREDOC_EOF, /* EOF before the heredoc terminator */
CTL_EK_LINE_TOO_LONG,
CTL_EK_LIMIT, /* too many args / body over CTL_MAX_ARG_BYTES */
CTL_EK_OOM
} ctl_error_kind_t;
typedef struct {
size_t calls_open;
size_t calls_ready;
size_t args_nbytes; /* arg <key> <n> */
size_t args_inline; /* arg <key> <value on the same line> */
size_t args_heredoc; /* arg <key> <<TAG ... TAG */
size_t pending_peak;
ctl_error_kind_t error_kind;
} ctl_parser_stats_t;
const char *ctl_error_kind_name(ctl_error_kind_t k);
typedef struct ctl_parser ctl_parser_t;
ctl_parser_t *ctl_parser_create(ctl_on_event_fn on_event, void *userdata);
@@ -91,6 +116,8 @@ size_t ctl_parser_pending_peak(const ctl_parser_t *p);
/* Reset for a new assistant turn. */
void ctl_parser_reset(ctl_parser_t *p);
void ctl_parser_stats(const ctl_parser_t *p, ctl_parser_stats_t *out);
#ifdef __cplusplus
}
#endif