detz: release v0.1.1
This commit is contained in:
@@ -0,0 +1 @@
|
||||
detz C++ port
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.1.0
|
||||
0.1.1
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
# cap
|
||||
@@ -0,0 +1 @@
|
||||
# mcp
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
namespace detz::comms {
|
||||
class Telegram { public: explicit Telegram(std::string token=""):tok_(tok_){} bool send(const std::string& chat, const std::string& msg) const; private: std::string tok_; };
|
||||
class Telegram { public: explicit Telegram(std::string token=""):tok_(std::move(token)){} bool send(const std::string& chat, const std::string& msg) const; private: std::string tok_; };
|
||||
class Installer { public: bool install(const std::string& target) const; };
|
||||
struct SysInfoData { std::string os, arch; };
|
||||
class SysInfo { public: SysInfoData collect() const; };
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <stdexcept>
|
||||
#include <stdexcept>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "sandbox.h"
|
||||
#include <cstdio>
|
||||
namespace detz::shell {
|
||||
Sandbox::Sandbox(std::string root, std::vector<std::string> allow) : root_(std::move(root)), allow_(std::move(allow)) {}
|
||||
bool Sandbox::allowed(const std::string& cmd) const {
|
||||
if (allow_.empty()) return true;
|
||||
for (auto& a : allow_) if (cmd.rfind(a, 0) == 0) return true;
|
||||
return false;
|
||||
}
|
||||
SandboxResult Sandbox::run(const std::string& cmd, int) {
|
||||
SandboxResult r;
|
||||
if (!allowed(cmd)) { r.code = 126; r.err = "denied by sandbox"; return r; }
|
||||
std::string full = "cd " + root_ + " && " + cmd + " 2>&1";
|
||||
FILE* p = ::popen(full.c_str(), "r");
|
||||
if (!p) { r.code = 127; r.err = "popen failed"; return r; }
|
||||
char buf[1024]; while (std::fgets(buf, sizeof buf, p)) r.out += buf;
|
||||
r.code = ::pclose(p);
|
||||
return r;
|
||||
}
|
||||
std::string curl_hint(const std::string& url) { return "curl -sS " + url; }
|
||||
} // namespace detz::shell
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace detz::shell {
|
||||
struct SandboxResult { int code{0}; std::string out; std::string err; };
|
||||
class Sandbox {
|
||||
public:
|
||||
explicit Sandbox(std::string root = "/tmp", std::vector<std::string> allow = {});
|
||||
SandboxResult run(const std::string& cmd, int timeout_ms = 5000);
|
||||
const std::string& root() const { return root_; }
|
||||
private:
|
||||
bool allowed(const std::string& cmd) const;
|
||||
std::string root_; std::vector<std::string> allow_;
|
||||
};
|
||||
std::string curl_hint(const std::string& url);
|
||||
} // namespace detz::shell
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
namespace detz::shell {
|
||||
struct ExecResult { int code{0}; std::string out; };
|
||||
class ShellSession {
|
||||
public:
|
||||
explicit ShellSession(std::string shell = "/bin/sh");
|
||||
ExecResult exec(const std::string& cmd, int timeout_ms = 5000);
|
||||
std::vector<std::string> segment_targets(const std::vector<std::string>& paths);
|
||||
std::vector<std::string> target_paths(const std::string& spec);
|
||||
private:
|
||||
std::string shell_;
|
||||
};
|
||||
} // namespace detz::shell
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -15,6 +15,7 @@ class Store {
|
||||
void exec(const std::string& sql);
|
||||
void migrate();
|
||||
void setup_fts();
|
||||
bool ok() const { return true; }
|
||||
int schema_version() const;
|
||||
int64_t add_record(const std::string& kind, const std::string& title, const std::string& content);
|
||||
bool update_record(int64_t id, const std::string& title, const std::string& content);
|
||||
@@ -27,12 +28,13 @@ class Store {
|
||||
};
|
||||
std::string truncate_text(const std::string& s, std::size_t limit);
|
||||
std::string spill_output(Store& st, const std::string& kind, const std::string& title, const std::string& text);
|
||||
std::string spilled_view(const std::string& text, int64_t id);
|
||||
std::string spilled_view(const std::string& text, int64_t id, std::size_t head = 2000, std::size_t tail = 2000);
|
||||
std::string spill_or_truncate(Store* st, const std::string& kind, const std::string& title, const std::string& text);
|
||||
class DebugLog {
|
||||
public:
|
||||
void push(const std::string& level, const std::string& msg);
|
||||
void info(const std::string& m); void warn(const std::string& m); void error(const std::string& m);
|
||||
const std::vector<std::string>& lines() const { return lines_; }
|
||||
private:
|
||||
std::vector<std::string> lines_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user