Add metadata validation script and module documentation

- Introduced a new Python script `check_agents_metadata.py` for validating agent metadata, including YAML parsing, rating ranges, and cross-references.
- Added usage instructions and exit codes for the script.
- Created a new markdown file `模块目录和功能说明.md` to outline the directory structure and functionality of the modules.
- Added a text file `说明此文件不可AI修改.txt` to specify that certain files should not be modified by AI, including important information about the `dstalk` framework and its modules.
This commit is contained in:
2026-05-31 00:00:58 +08:00
parent 3cc9ee95e4
commit f2da0f2ed4
43 changed files with 2467 additions and 800 deletions

View File

@@ -1,3 +1,9 @@
/* @file config_store.cpp
* @brief ConfigStore implementation: TOML parsing, thread-safe get/set with thread-local safety.
* ConfigStore 实现TOML 解析、线程安全的 get/set基于 thread-local 安全机制)。
* Copyright (c) 2026 dstalk contributors. GPLv3.
*/
#include "config_store.hpp"
#include "../../plugins/config/include/toml_parse.h"
@@ -8,6 +14,7 @@
namespace dstalk {
// 在互斥锁下加载并解析 TOML 文件到键值存储 / Load and parse a TOML file into the key-value store under mutex.
int ConfigStore::load_file(const char* path)
{
if (!path) return -1;
@@ -19,7 +26,7 @@ int ConfigStore::load_file(const char* path)
ss << file.rdbuf();
std::string data = ss.str();
// W12.2: Use shared TOML parser (de-duplicated from config_plugin.cpp)
// W12.2: 使用共享 TOML 解析器(从 config_plugin.cpp 去重) / Use shared TOML parser (de-duplicated from config_plugin.cpp)
toml::parse(data, [this](const std::string& key, const std::string& value) {
std::lock_guard<std::mutex> lock(mutex_);
data_[key] = value;
@@ -28,6 +35,7 @@ int ConfigStore::load_file(const char* path)
return 0;
}
// 检索配置值,返回线程本地副本以避免 c_str() 悬空 / Retrieve config value, returning a thread-local copy to avoid dangling c_str().
const char* ConfigStore::get(const char* key) const
{
if (!key) return nullptr;
@@ -35,7 +43,9 @@ const char* ConfigStore::get(const char* key) const
auto it = data_.find(key);
if (it == data_.end()) return nullptr;
// W12.2: Copy to thread-local buffer before releasing lock.
// W12.2: 在释放锁之前复制到线程本地缓冲区 /
// Copy to thread-local buffer before releasing lock.
// 防止当并发 set() 触发 std::string 重新分配时 c_str() 悬空 /
// Prevents c_str() dangling when concurrent set() on the same key
// triggers std::string reallocation (W11.2 audit Finding 3).
thread_local std::string tls_cached;
@@ -43,15 +53,17 @@ const char* ConfigStore::get(const char* key) const
return tls_cached.c_str();
}
// 以 std::string 值类型检索配置(安全的值副本)/ Retrieve config value as an owned std::string (safe by-value copy).
std::string ConfigStore::get_copy(const char* key) const
{
if (!key) return {};
std::lock_guard<std::mutex> lock(mutex_);
auto it = data_.find(key);
if (it == data_.end()) return {};
return it->second; // copy-constructed under lock, always safe
return it->second; // 在锁下复制构造,始终安全 / copy-constructed under lock, always safe
}
// 在锁下设置配置键值对 / Set a config key-value pair under lock.
int ConfigStore::set(const char* key, const char* value)
{
if (!key || !value) return -1;