dead code elim
This commit is contained in:
+11
-2
@@ -134,6 +134,15 @@ Cfg get_cfg(std::string_view path) {
|
||||
}
|
||||
|
||||
int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
|
||||
/* Strip a single pair of surrounding quotes so a value containing spaces can
|
||||
* be passed as e.g. "a b" without the quote characters becoming part of the
|
||||
* stored value. */
|
||||
std::string vstr(val);
|
||||
if (vstr.size() >= 2 &&
|
||||
((vstr.front() == '"' && vstr.back() == '"') ||
|
||||
(vstr.front() == '\'' && vstr.back() == '\''))) {
|
||||
vstr = vstr.substr(1, vstr.size() - 2);
|
||||
}
|
||||
std::vector<std::string> lines;
|
||||
{
|
||||
std::string content;
|
||||
@@ -157,7 +166,7 @@ int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
|
||||
std::string_view keyPart = sv.substr(k, eq - k);
|
||||
while (!keyPart.empty() && std::isspace((unsigned char)keyPart.back())) keyPart.remove_suffix(1);
|
||||
if (keyPart == key) {
|
||||
line = sfmt("%s=%s\n", std::string(key).c_str(), std::string(val).c_str());
|
||||
line = sfmt("%s=%s\n", std::string(key).c_str(), vstr.c_str());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +175,7 @@ int set_cfg(std::string_view path, std::string_view key, std::string_view val) {
|
||||
std::string &last = lines.back();
|
||||
if (!last.empty() && last.back() != '\n') last += '\n';
|
||||
}
|
||||
lines.push_back(sfmt("%s=%s\n", std::string(key).c_str(), std::string(val).c_str()));
|
||||
lines.push_back(sfmt("%s=%s\n", std::string(key).c_str(), vstr.c_str()));
|
||||
}
|
||||
std::string out_buf;
|
||||
for (auto &line : lines) out_buf += line;
|
||||
|
||||
@@ -118,10 +118,6 @@ static bool trim_is_empty(std::string_view s) {
|
||||
while (i < s.size() && (s[i] == ' ' || s[i] == '\n' || s[i] == '\r' || s[i] == '\t')) i++;
|
||||
return i == s.size();
|
||||
}
|
||||
static std::string last_role(Messages &msgs) {
|
||||
if (msgs.items.empty()) return "";
|
||||
return msgs.items.back().role;
|
||||
}
|
||||
|
||||
/* ----------------------------- AL loop -------------------------------- */
|
||||
static int AL(Cfg &cfg, Messages &msgs, Usage &out, volatile int *interrupted, std::string *err) {
|
||||
@@ -280,12 +276,6 @@ static int run_turn(Cfg &cfg, Messages &msgs, Usage &usage, std::string *err, vo
|
||||
*interrupted = 0;
|
||||
usage = Usage{};
|
||||
int rc = AL(cfg, msgs, usage, interrupted, err);
|
||||
if (last_role(msgs) == "tool") {
|
||||
Message cont; cont.role = "user"; cont.content = "continue";
|
||||
msgs.items.push_back(cont);
|
||||
cprint("[auto continue: last message was a tool result]\n", std::array{33});
|
||||
rc = AL(cfg, msgs, usage, interrupted, err);
|
||||
}
|
||||
if (rc != 0) {
|
||||
if (*interrupted) { cprint("\n[interrupted]\n", std::array{33}); }
|
||||
else { cprint("\n[error: ", std::array{31}); cprint((!err || err->empty()) ? "error" : *err, std::array{31}); cprint("]\n", std::array{31}); }
|
||||
|
||||
Reference in New Issue
Block a user