Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
258 lines
6.6 KiB
C++
258 lines
6.6 KiB
C++
#include "admission.hpp"
|
|
|
|
#include <sstream>
|
|
#include <utility>
|
|
|
|
namespace admission {
|
|
namespace {
|
|
|
|
std::vector<std::string> tokenize(const std::string &line)
|
|
{
|
|
std::istringstream input(line);
|
|
std::vector<std::string> tokens;
|
|
std::string token;
|
|
while (input >> token) {
|
|
tokens.push_back(token);
|
|
}
|
|
return tokens;
|
|
}
|
|
|
|
std::string prefix(const char *operation, const std::string &name)
|
|
{
|
|
return std::string(operation) + " " + name + " ";
|
|
}
|
|
|
|
std::string triple_prefix(const char *operation, const std::string &name,
|
|
const std::string &key)
|
|
{
|
|
return std::string(operation) + " " + name + " " + key + " ";
|
|
}
|
|
|
|
bool parse_policy_fields(const std::vector<std::string> &tokens, Policy &policy)
|
|
{
|
|
return parse_policy(tokens, 2, policy);
|
|
}
|
|
|
|
std::string client_text(const ClientView &view)
|
|
{
|
|
std::ostringstream output;
|
|
output << view.start << ' ' << view.last << ' ' << view.used << ' '
|
|
<< view.admitted << ' ' << view.rejected;
|
|
return output.str();
|
|
}
|
|
|
|
std::string statistics_text(const Statistics &value)
|
|
{
|
|
std::ostringstream output;
|
|
output << value.clients << ' ' << value.admitted << ' ' << value.rejected
|
|
<< ' ' << value.policy.limit << ' ' << value.policy.window << ' '
|
|
<< value.policy.capacity;
|
|
return output.str();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
Engine *Session::find(const std::string &name)
|
|
{
|
|
auto found = engines_.find(name);
|
|
if (found == engines_.end()) {
|
|
return nullptr;
|
|
}
|
|
return &found->second;
|
|
}
|
|
|
|
const Engine *Session::find(const std::string &name) const
|
|
{
|
|
auto found = engines_.find(name);
|
|
if (found == engines_.end()) {
|
|
return nullptr;
|
|
}
|
|
return &found->second;
|
|
}
|
|
|
|
std::vector<std::string> Session::names() const
|
|
{
|
|
std::vector<std::string> result;
|
|
for (const auto &entry : engines_) {
|
|
result.push_back(entry.first);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::string Session::execute(const std::string &line)
|
|
{
|
|
std::vector<std::string> tokens = tokenize(line);
|
|
if (tokens.empty()) {
|
|
return {};
|
|
}
|
|
if (!tokens[0].empty() && tokens[0][0] == '#') {
|
|
return {};
|
|
}
|
|
if (tokens[0] == "NEW") {
|
|
return execute_new(tokens);
|
|
}
|
|
if (tokens[0] == "REQ") {
|
|
return execute_request(tokens);
|
|
}
|
|
if (tokens[0] == "CFG") {
|
|
return execute_config(tokens);
|
|
}
|
|
if (tokens[0] == "GET") {
|
|
return execute_get(tokens);
|
|
}
|
|
if (tokens[0] == "DROP") {
|
|
return execute_drop(tokens);
|
|
}
|
|
if (tokens[0] == "RESET") {
|
|
return execute_reset(tokens);
|
|
}
|
|
if (tokens[0] == "STATS") {
|
|
return execute_stats(tokens);
|
|
}
|
|
if (tokens[0] == "DEL") {
|
|
return execute_delete(tokens);
|
|
}
|
|
if (tokens[0] == "LIST") {
|
|
return execute_list(tokens);
|
|
}
|
|
return "ERR PARSE";
|
|
}
|
|
|
|
std::string Session::execute_new(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 5) {
|
|
return "ERR PARSE";
|
|
}
|
|
const std::string &name = tokens[1];
|
|
Policy policy;
|
|
if (!parse_policy_fields(tokens, policy)) {
|
|
return "ERR NUMBER";
|
|
}
|
|
if (!valid_key(name) || !valid_policy(policy)) {
|
|
return prefix("NEW", name) + "POLICY";
|
|
}
|
|
if (find(name) != nullptr) {
|
|
return prefix("NEW", name) + "EXISTS";
|
|
}
|
|
engines_.emplace(name, Engine(policy));
|
|
return prefix("NEW", name) + "OK";
|
|
}
|
|
|
|
std::string Session::execute_request(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 4) {
|
|
return "ERR PARSE";
|
|
}
|
|
const std::string &name = tokens[1];
|
|
const std::string &key = tokens[2];
|
|
std::uint64_t tick = 0;
|
|
if (!parse_u64(tokens[3], tick)) {
|
|
return "ERR NUMBER";
|
|
}
|
|
Engine *engine = find(name);
|
|
if (engine == nullptr) {
|
|
return triple_prefix("REQ", name, key) + "NO_INSTANCE";
|
|
}
|
|
return triple_prefix("REQ", name, key) + request_name(engine->request(key, tick));
|
|
}
|
|
|
|
std::string Session::execute_config(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 5) {
|
|
return "ERR PARSE";
|
|
}
|
|
const std::string &name = tokens[1];
|
|
Policy policy;
|
|
if (!parse_policy_fields(tokens, policy)) {
|
|
return "ERR NUMBER";
|
|
}
|
|
Engine *engine = find(name);
|
|
if (engine == nullptr) {
|
|
return prefix("CFG", name) + "NO_INSTANCE";
|
|
}
|
|
return prefix("CFG", name) + config_name(engine->configure(policy));
|
|
}
|
|
|
|
std::string Session::execute_get(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 3) {
|
|
return "ERR PARSE";
|
|
}
|
|
const std::string &name = tokens[1];
|
|
const std::string &key = tokens[2];
|
|
const Engine *engine = find(name);
|
|
if (engine == nullptr) {
|
|
return triple_prefix("GET", name, key) + "NO_INSTANCE";
|
|
}
|
|
ClientView view;
|
|
if (!engine->inspect(key, view)) {
|
|
return triple_prefix("GET", name, key) + "NONE";
|
|
}
|
|
return triple_prefix("GET", name, key) + client_text(view);
|
|
}
|
|
|
|
std::string Session::execute_drop(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 3) {
|
|
return "ERR PARSE";
|
|
}
|
|
const std::string &name = tokens[1];
|
|
const std::string &key = tokens[2];
|
|
Engine *engine = find(name);
|
|
if (engine == nullptr) {
|
|
return triple_prefix("DROP", name, key) + "NO_INSTANCE";
|
|
}
|
|
return triple_prefix("DROP", name, key) + drop_name(engine->drop(key));
|
|
}
|
|
|
|
std::string Session::execute_reset(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 2) {
|
|
return "ERR PARSE";
|
|
}
|
|
Engine *engine = find(tokens[1]);
|
|
if (engine == nullptr) {
|
|
return prefix("RESET", tokens[1]) + "NO_INSTANCE";
|
|
}
|
|
engine->reset();
|
|
return prefix("RESET", tokens[1]) + "OK";
|
|
}
|
|
|
|
std::string Session::execute_stats(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 2) {
|
|
return "ERR PARSE";
|
|
}
|
|
const Engine *engine = find(tokens[1]);
|
|
if (engine == nullptr) {
|
|
return prefix("STATS", tokens[1]) + "NO_INSTANCE";
|
|
}
|
|
return prefix("STATS", tokens[1]) + statistics_text(engine->statistics());
|
|
}
|
|
|
|
std::string Session::execute_delete(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 2) {
|
|
return "ERR PARSE";
|
|
}
|
|
if (engines_.erase(tokens[1]) == 0) {
|
|
return prefix("DEL", tokens[1]) + "MISSING";
|
|
}
|
|
return prefix("DEL", tokens[1]) + "OK";
|
|
}
|
|
|
|
std::string Session::execute_list(const std::vector<std::string> &tokens)
|
|
{
|
|
if (tokens.size() != 1) {
|
|
return "ERR PARSE";
|
|
}
|
|
std::string result = "LIST";
|
|
for (const std::string &name : names()) {
|
|
result += ' ';
|
|
result += name;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
} // namespace admission
|