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
+52 -11
View File
@@ -42,12 +42,25 @@ add_custom_target(sashidown DEPENDS "${SASHIDOWN_A}")
find_package(CURL REQUIRED)
find_package(Threads REQUIRED)
set(CST_SOURCES
set(CJSON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/cjson")
set(CST_CORE_SOURCES
vendor/cjson/cJSON.c
src/util.c
src/ctl_parse.c
src/os_compat.c
src/sandbox.c
src/session.c
src/tools/tools.c
src/tools/patch.c
src/tools/registry.c
src/tools/fs_tools.c
src/tools/agent_tools.c
src/tools/web.c
src/tools/diff.c
src/undo.c
src/permissions.c
src/settings.c
src/llm_openai.c
src/agent_loop.c
src/agent_store.c
@@ -55,8 +68,9 @@ set(CST_SOURCES
src/creds.c
src/mm_tool.c
src/models.c
src/main.c
src/metrics.c
)
set(CST_SOURCES ${CST_CORE_SOURCES} src/main.c)
if(CST_BUILD_TUI)
list(APPEND CST_SOURCES src/tui.c)
@@ -70,6 +84,7 @@ add_dependencies(cst-agent sashidown)
target_include_directories(cst-agent PRIVATE
include
"${SD_DIR}/include"
"${CJSON_DIR}"
)
target_compile_definitions(cst-agent PRIVATE _GNU_SOURCE)
@@ -128,19 +143,40 @@ endif()
# --- tests ---
enable_testing()
foreach(t test_ctl_frontier test_json_baseline test_replay_starvation test_mm_tool)
if(t STREQUAL test_ctl_frontier)
add_executable(${t} tests/test_ctl_frontier.c src/ctl_parse.c)
set(_CST_SMALL_TESTS test_ctl_frontier test_ctl_heredoc test_json_baseline
test_replay_starvation test_replay_real test_mm_tool)
foreach(t ${_CST_SMALL_TESTS})
if(t STREQUAL test_ctl_frontier OR t STREQUAL test_ctl_heredoc)
add_executable(${t} tests/${t}.c src/ctl_parse.c)
elseif(t STREQUAL test_json_baseline)
add_executable(${t} tests/test_json_baseline.c src/json_baseline.c)
elseif(t STREQUAL test_replay_starvation)
add_executable(${t} tests/test_replay_starvation.c src/ctl_parse.c src/json_baseline.c)
add_executable(${t} tests/${t}.c src/json_baseline.c vendor/cjson/cJSON.c)
elseif(t STREQUAL test_replay_starvation OR t STREQUAL test_replay_real)
add_executable(${t} tests/${t}.c src/ctl_parse.c src/json_baseline.c vendor/cjson/cJSON.c)
else()
add_executable(${t} tests/test_mm_tool.c src/mm_tool.c)
endif()
target_include_directories(${t} PRIVATE include)
target_include_directories(${t} PRIVATE include "${CJSON_DIR}")
target_compile_definitions(${t} PRIVATE _GNU_SOURCE)
add_test(NAME ${t} COMMAND ${t})
if(NOT WIN32)
target_link_libraries(${t} PRIVATE m)
endif()
add_test(NAME ${t} COMMAND ${t} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endforeach()
# Tests that link the whole core (no TUI).
foreach(t test_llm_body test_sse_decode test_apply_patch test_session_roundtrip
test_shell test_diff test_tools_fs test_registry
test_undo test_config)
add_executable(${t} tests/${t}.c ${CST_CORE_SOURCES})
target_include_directories(${t} PRIVATE include "${CJSON_DIR}")
target_compile_definitions(${t} PRIVATE _GNU_SOURCE)
target_link_libraries(${t} PRIVATE CURL::libcurl Threads::Threads)
if(NOT WIN32)
target_link_libraries(${t} PRIVATE m)
else()
target_link_libraries(${t} PRIVATE ws2_32 crypt32 secur32 bcrypt advapi32)
endif()
add_test(NAME ${t} COMMAND ${t} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
endforeach()
# --- busybox bundle helpers ---
@@ -154,7 +190,12 @@ if(CST_BUNDLE_BUSYBOX)
endif()
endif()
install(TARGETS cst-agent RUNTIME DESTINATION .)
if(WIN32)
install(TARGETS cst-agent RUNTIME DESTINATION .)
else()
include(GNUInstallDirs)
install(TARGETS cst-agent RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
message(STATUS "Compiler: ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER}")
message(STATUS "CST_BUILD_TUI=${CST_BUILD_TUI}")