Files
WHC 2fde898da0 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.
2026-10-05 01:47:01 +08:00

126 lines
3.1 KiB
C

#ifndef CTL_H
#define CTL_H
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CTL_MAX_LINE
#define CTL_MAX_LINE 4096
#endif
#ifndef CTL_MAX_ARGS
#define CTL_MAX_ARGS 16
#endif
#ifndef CTL_MAX_ARG_BYTES
#define CTL_MAX_ARG_BYTES (1024 * 1024)
#endif
#ifndef CTL_MAX_ID
#define CTL_MAX_ID 64
#endif
#ifndef CTL_MAX_NAME
#define CTL_MAX_NAME 64
#endif
#ifndef CTL_MAX_KEY
#define CTL_MAX_KEY 64
#endif
typedef enum {
CTL_OK = 0,
CTL_ERR_CONTRACT = 1, /* left L0_tool */
CTL_ERR_NOMEM = 2,
CTL_ERR_LIMIT = 3
} ctl_status_t;
typedef enum {
CTL_EV_NONE = 0,
CTL_EV_CALL_OPEN, /* id+name confirmed */
CTL_EV_ARG, /* one arg fully confirmed */
CTL_EV_CALL_READY, /* end confirmed — safe to execute */
CTL_EV_TEXT, /* non-CTL confirmed text (outside call) */
CTL_EV_ERROR
} ctl_event_type_t;
typedef struct {
char key[CTL_MAX_KEY];
char *value;
size_t value_len;
} ctl_arg_t;
typedef struct {
char id[CTL_MAX_ID];
char name[CTL_MAX_NAME];
ctl_arg_t args[CTL_MAX_ARGS];
int nargs;
} ctl_tool_call_t;
typedef struct {
ctl_event_type_t type;
const ctl_tool_call_t *call; /* valid for CALL_* / ARG */
const char *text; /* for TEXT */
size_t text_len;
const char *error; /* for ERROR */
} ctl_event_t;
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);
void ctl_parser_destroy(ctl_parser_t *p);
/* Feed UTF-8 bytes. Emits only confirmed events. */
ctl_status_t ctl_parser_feed(ctl_parser_t *p, const char *data, size_t len);
/* EOF: flush; incomplete call => ERROR (no execute). */
ctl_status_t ctl_parser_finish(ctl_parser_t *p);
/* Bytes currently pending (unconfirmed). */
size_t ctl_parser_pending(const ctl_parser_t *p);
/* Peak pending observed (for experiments). */
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
#endif /* CTL_H */