Files
CST-agent/src/json_baseline.c
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

46 lines
1.5 KiB
C

#include "cJSON.h"
#include "cst_agent.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* JSON-buffer baseline: {"name":"...","arguments":{...}} is executable only
* once cJSON can parse the whole object (NOT bounded CST: nothing inside an
* unfinished object is ever confirmed). */
int cst_json_try_parse_tool(const char *buf, size_t len, cst_json_tool_t *out) {
if (!buf || !out)
return 0;
memset(out, 0, sizeof(*out));
const char *p = buf, *end = buf + len;
while (p < end) {
if (*p != '{') {
p++;
continue;
}
const char *obj_end = NULL;
cJSON *o = cJSON_ParseWithLengthOpts(p, (size_t)(end - p), &obj_end, 0);
if (!o)
return 0; /* incomplete/invalid: the starvation failure mode */
const cJSON *name = cJSON_GetObjectItemCaseSensitive(o, "name");
const cJSON *args = cJSON_GetObjectItemCaseSensitive(o, "arguments");
int ok = 0;
if (cJSON_IsString(name) && args &&
strlen(name->valuestring) < sizeof(out->name)) {
char *a = cJSON_IsString(args) ? NULL : cJSON_PrintUnformatted(args);
const char *av = a ? a : (cJSON_IsString(args) ? args->valuestring : "");
if (strlen(av) < sizeof(out->arguments_json)) {
snprintf(out->name, sizeof(out->name), "%s", name->valuestring);
snprintf(out->arguments_json, sizeof(out->arguments_json), "%s", av);
out->ok = ok = 1;
}
free(a);
}
cJSON_Delete(o);
if (ok)
return 1;
p = obj_end && obj_end > p ? obj_end : p + 1;
}
return 0;
}