Files
CST-agent/src/tools/tools_internal.h
T
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

64 lines
3.1 KiB
C

#ifndef CST_TOOLS_INTERNAL_H
#define CST_TOOLS_INTERNAL_H
#include "cst_tools.h"
#include "cst_util.h"
#define READ_FILE_MAX (2 * 1024 * 1024)
/* Value of key, or NULL when absent. */
const char *tool_arg(const ctl_tool_call_t *call, const char *key);
const char *tool_arg_n(const ctl_tool_call_t *call, const char *key,
size_t *len);
/* Integer arg, def when absent or empty. */
long tool_arg_long(const ctl_tool_call_t *call, const char *key, long def);
int tool_arg_bool(const ctl_tool_call_t *call, const char *key, int def);
int tool_set_result(cst_tool_result_t *r, const char *s, int code);
int tool_set_resultf(cst_tool_result_t *r, int code, const char *fmt, ...);
int tool_take_buf(cst_tool_result_t *r, cst_buf_t *b, int code);
/* Whole file (NULL when missing, unreadable or larger than max>0). */
char *tool_slurp(const char *full, size_t *out_len, size_t max);
int tool_write_whole(const char *full, const char *data, size_t n);
void tool_ensure_parent_dirs(const char *workspace_root, const char *rel);
void tool_append_diff(cst_buf_t *b, const char *relpath, const char *oldc,
size_t olen, const char *newc, size_t nlen);
int tool_is_binary(const char *s, size_t n);
/* Workspace-relative display form of an absolute resolved path. */
const char *tool_rel(const char *workspace_real, const char *full);
int cst_tool_read_file2(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_list_dir(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_glob(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_grep(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_edit_file(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_delete_file(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_move_file(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_todo_write(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_ask_user(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_tool_web_fetch(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
cst_tool_result_t *r);
int cst_preview_write_file(const cst_tool_ctx_t *ctx,
const ctl_tool_call_t *c, char **out);
int cst_preview_apply_patch(const cst_tool_ctx_t *ctx,
const ctl_tool_call_t *c, char **out);
int cst_preview_edit_file(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
char **out);
int cst_preview_delete_file(const cst_tool_ctx_t *ctx,
const ctl_tool_call_t *c, char **out);
int cst_preview_move_file(const cst_tool_ctx_t *ctx, const ctl_tool_call_t *c,
char **out);
#endif