From ac4df725ef42db8d4f9206d2ce2066081223d1c5 Mon Sep 17 00:00:00 2001 From: retoor Date: Sat, 24 Oct 2026 06:43:33 +0200 Subject: [PATCH] detz: release v0.1.1 --- taicpp/SPEC | 1 + taicpp/VERSION | 2 +- taicpp/docs/cap.md | 1 + taicpp/docs/mcp.md | 1 + taicpp/src/comms/comms.h | 2 +- taicpp/src/llm/llm.h | 1 + taicpp/src/shell/sandbox.cpp | 21 +++++++++++++++++++++ taicpp/src/shell/sandbox.h | 16 ++++++++++++++++ taicpp/src/shell/session.h | 15 +++++++++++++++ taicpp/src/store/store.h | 6 ++++-- 10 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 taicpp/SPEC create mode 100644 taicpp/docs/cap.md create mode 100644 taicpp/docs/mcp.md create mode 100644 taicpp/src/shell/sandbox.cpp create mode 100644 taicpp/src/shell/sandbox.h create mode 100644 taicpp/src/shell/session.h diff --git a/taicpp/SPEC b/taicpp/SPEC new file mode 100644 index 0000000..366cad2 --- /dev/null +++ b/taicpp/SPEC @@ -0,0 +1 @@ +detz C++ port diff --git a/taicpp/VERSION b/taicpp/VERSION index 6e8bf73..17e51c3 100644 --- a/taicpp/VERSION +++ b/taicpp/VERSION @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/taicpp/docs/cap.md b/taicpp/docs/cap.md new file mode 100644 index 0000000..cfc19d2 --- /dev/null +++ b/taicpp/docs/cap.md @@ -0,0 +1 @@ +# cap diff --git a/taicpp/docs/mcp.md b/taicpp/docs/mcp.md new file mode 100644 index 0000000..cac8423 --- /dev/null +++ b/taicpp/docs/mcp.md @@ -0,0 +1 @@ +# mcp diff --git a/taicpp/src/comms/comms.h b/taicpp/src/comms/comms.h index c02cb9b..4e31f83 100644 --- a/taicpp/src/comms/comms.h +++ b/taicpp/src/comms/comms.h @@ -6,7 +6,7 @@ #include #include 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; }; diff --git a/taicpp/src/llm/llm.h b/taicpp/src/llm/llm.h index c20964c..ae0e093 100644 --- a/taicpp/src/llm/llm.h +++ b/taicpp/src/llm/llm.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/taicpp/src/shell/sandbox.cpp b/taicpp/src/shell/sandbox.cpp new file mode 100644 index 0000000..85d6205 --- /dev/null +++ b/taicpp/src/shell/sandbox.cpp @@ -0,0 +1,21 @@ +#include "sandbox.h" +#include +namespace detz::shell { +Sandbox::Sandbox(std::string root, std::vector 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 diff --git a/taicpp/src/shell/sandbox.h b/taicpp/src/shell/sandbox.h new file mode 100644 index 0000000..33f5edc --- /dev/null +++ b/taicpp/src/shell/sandbox.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include +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 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 allow_; +}; +std::string curl_hint(const std::string& url); +} // namespace detz::shell diff --git a/taicpp/src/shell/session.h b/taicpp/src/shell/session.h new file mode 100644 index 0000000..e3c1dd6 --- /dev/null +++ b/taicpp/src/shell/session.h @@ -0,0 +1,15 @@ +#pragma once +#include +#include +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 segment_targets(const std::vector& paths); + std::vector target_paths(const std::string& spec); + private: + std::string shell_; +}; +} // namespace detz::shell diff --git a/taicpp/src/store/store.h b/taicpp/src/store/store.h index c398cfb..24e2d06 100644 --- a/taicpp/src/store/store.h +++ b/taicpp/src/store/store.h @@ -1,6 +1,6 @@ #pragma once +#include #include -#include #include #include #include @@ -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& lines() const { return lines_; } private: std::vector lines_; };