W21: anthropic Stream+Tools + --prompt batch + sanitizer fix + plugin unit tests (W21.1-W21.6)
Some checks failed
CI / Determine matrix (push) Has been cancelled
CI / ${{ matrix.os }} / ${{ matrix.build_type }} (push) Has been cancelled
CI / Sanitizer (ASan+UBSan) / ubuntu-24.04 (push) Has been cancelled

- W21.1: ci-sanitize preset 独立 Linux-clang + ci-threadsan (TSan)
- W21.2: anthropic tool_use content_block 解析 + configure 缓存 tools_json
- W21.3: --prompt 非交互批处理模式
- W21.4: session auto-save 失败告警 + 当前目录 fallback
- W21.5: smoke 补 tool_calls 边界用例 4 块 12 断言
- W21.6: anthropic 11 块 78 CHECK + deepseek 12 块 78 CHECK

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:40:58 +08:00
parent 20ead86e88
commit b2b381b9b3
14 changed files with 1671 additions and 34 deletions

View File

@@ -401,11 +401,14 @@ int main(int argc, char* argv[])
bool pipe_mode = (isatty(fileno(stdin)) == 0);
#endif
bool batch_mode = false;
const char* prompt_arg = nullptr;
if (!pipe_mode) {
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--batch") == 0) {
batch_mode = true;
break;
} else if (std::strcmp(argv[i], "--prompt") == 0 && i + 1 < argc && argv[i+1][0] != '-') {
prompt_arg = argv[++i];
batch_mode = true;
}
}
}
@@ -421,12 +424,13 @@ int main(int argc, char* argv[])
// 查找配置文件
const char* config_path = nullptr;
if (argc >= 2) {
// 跳过 --batch 标志
// 跳过 --batch / --prompt 标志
for (int i = 1; i < argc; ++i) {
if (std::strcmp(argv[i], "--batch") != 0) {
if (std::strcmp(argv[i], "--batch") != 0 && std::strcmp(argv[i], "--prompt") != 0) {
config_path = argv[i];
break;
}
if (std::strcmp(argv[i], "--prompt") == 0 && i + 1 < argc) ++i;
}
}
if (!config_path) {
@@ -518,6 +522,35 @@ int main(int argc, char* argv[])
}
}
// ---- --prompt 批处理模式 (非交互) ----
if (prompt_arg) {
if (prompt_arg[0] == '\0') {
std::fprintf(stderr, "empty prompt\n");
dstalk_shutdown();
return EXIT_FATAL;
}
if (!g_ai || !g_session) {
std::fprintf(stderr, CLR_RED "[ERROR] AI or session service unavailable\n" CLR_RESET);
dstalk_shutdown();
return EXIT_CONFIG;
}
int history_count = 0;
const dstalk_message_t* history = g_session->history(&history_count);
dstalk_chat_result_t result = g_ai->chat(history, history_count, prompt_arg, nullptr);
if (result.ok) {
std::printf("%s\n", result.content ? result.content : "");
g_ai->free_result(&result);
dstalk_shutdown();
return EXIT_OK;
} else {
std::fprintf(stderr, CLR_RED "[ERROR] AI error: %s\n" CLR_RESET,
result.error ? result.error : "unknown");
g_ai->free_result(&result);
dstalk_shutdown();
return EXIT_FATAL;
}
}
char buffer[8192];
while (true) {
// B1: 检查退出标志