Files
moloapp/docs/embed-taicpp-2026-10-26.md
T
retoor 0595284fe3 feat(doos): add container runtime, audit cases, example demo and tests
- New rootless doos container runtime: sandbox, cgroup, network, images, hardening, davmount, CLI plus molo integration
- 18 CVE audit reproductions with READMEs and Makefiles
- Example DoosDemo routes, IndexCatalog, static assets, spec update
- CLI serve on 0.0.0.0:8000, arg parser, dev server improvements
- Runtime HTTP fixes, supervisor isolation backend
- Tests for doos, example doos routes, CLI serve; suite count 261 to 265
2026-11-06 04:36:00 +01:00

4.8 KiB
Raw Blame History

Static embeddability of ../tai/taicpp - research report (2026-10-26)

Verdict

Yes. taicpp builds build/libdetz.a (36 MB, verified 2026-10-26) excluding main.o, plus a fully-static build/detz-static (13.5 MB). Link it into molo and inject context via Agent::update_system() / run_turn().

1. Verified tree

  • taicpp/main.cpp (20 lines): cli::Parser::parseOpts → glue::GlueApp::run → AppBundle. Not in archive.
  • taicpp/src/: 25 modules; agent core src/agent/agent.{h,cpp}, prompt bytes src/agent/data.{h,cpp} (generated by src/agent/gen/gen_data.py from tai.py), config src/agent/agent_config.h, DI adapters src/glue/*_adapter.cpp, entry src/glue/glue_app.{h,cpp} + app_bundle.{h,cpp}.
  • taicpp/third_party/: curl/libcurl.a, sqlite/libsqlite3.a, jitterentropy/libjitterentropy.a (vendored, statically linked).
  • Correction: earlier subagent-2 claim "libdetz.a does NOT exist" was wrong - it inspected moloapp (build/molo, libai.a), not taicpp. ls -la confirms build/libdetz.a exists.

2. Makefile targets (taicpp/Makefile)

  • Line 27: LIB = $(BUILD)/libdetz.a; all → build/detz (dynamic: -lsqlite3 -lcurl -lz -pthread -lutil).
  • Lines 48–49 static:: g++ -pthread -static main.o ALL_OBJS third_party/curl/libcurl.a third_party/sqlite/libsqlite3.a -lssl -lcrypto third_party/jitterentropy/libjitterentropy.a -lzstd -lz -lnghttp2 -lpsl -lbrotlidec -lidn2 -lrtmp -o build/detz-static.
  • Line 52 comment: every test links tests/<name>.cpp against build/libdetz.a.
  • Needs MOLOAPP_SRC include (../../moloapp/src) + all src/*/ as -I.
INCS=$(ls -d ../tai/taicpp/src/*/ | sed 's/^/-I/')
g++ -std=c++23 $INCS -I../tai/taicpp -I../tai/taicpp/src \
  your_molo_obj.o build/libdetz.a \
  third_party/curl/libcurl.a third_party/sqlite/libsqlite3.a \
  third_party/jitterentropy/libjitterentropy.a \
  -lssl -lcrypto -lzstd -lz -lnghttp2 -lpsl -lbrotlidec -lidn2 -lrtmp \
  -lsqlite3 -lcurl -lz -pthread -lutil -o molo

Probe /tmp/embed_probe.cpp calling detz::agent::data::DefaultSystem() linked OK (104 KB binary).

4. Context-injection hooks (verified signatures + probe)

  • src/agent/agent.h:64 std::string system_message;
  • src/agent/agent.h:90 void update_system(const std::string& text); - sets system_message, persists via store->save_system/save_bot_system, calls apply_system(), logs event (agent.cpp:353-359).
  • src/agent/agent.cpp:301 void Agent::apply_system() - composes system_message + skill_catalog + tool_catalog + orientation_block + capability_block + AutonomousNote.
  • src/agent/agent.h:124 std::string run_turn(const std::string& text, bool capture=false, int max_steps=MAX_STEPS, bool routed=false); - per-turn injection point (prepend molo context to text).
  • src/agent/data.h:13-14 DefaultSystem()/MergeSystem() - byte-exact base prompt; permanent edits go via src/agent/gen/gen_data.py.
  • src/agent/agent_config.h struct AgentConfig : llm::LlmConfig - profile, db_path, history_path, auto_approve.
  • Probe /tmp/embed_ctx.cpp: DefaultSystem() + "\n\n# Molo extra context\n..." → CTX_OK base=2796 total=2869, asserts substring present. Compiled + ran OK against libdetz.a.
  • Minimal embed:
#include "agent/agent.h"
detz::agent::AgentConfig cfg; /* db_path, profile, ... */
detz::agent::Agent agent(cfg, myPorts); // StorePort etc., see src/glue/*_adapter.cpp
agent.update_system(detz::agent::data::DefaultSystem() + "\n\n# Molo extra context\n" + myCtx);
agent.run_turn(userInput);

5. External sources (static-embedding practice)

  1. AwesomeModernCPP - Static Libraries: Packaging with ar and Linking with -l/-L - ar rcs replace-and-insert semantics. https://awesome-embedded-learning-studio.github.io/Tutorial_AwesomeModernCPP/en/compilation/06-static-libraries (retrieved 2026-10-26)
  2. CodeGenes - Best Practices for Wrapping C++ Class APIs for C/FFI (2026-01-19): opaque types, extern "C", no exceptions across boundary, error codes. https://www.codegenes.net/blog/wrapping-c-class-api-for-c-consumption/ (retrieved 2026-10-26)
  3. zackli.ai - How C/C++ Bindings Work: ABI and FFI (2026-07-15): C ABI as interop standard, extern "C" linkage, opaque handles, function tables. https://zackli.ai/blog/c-abi-ffi/ (retrieved 2026-10-26)
  4. w3tutorials - How to Develop a C Wrapper API for Object-Oriented C++ Code (2026-01-16): C wrapper with opaque pointer + extern "C" + careful error handling. https://www.w3tutorials.net/blog/developing-c-wrapper-api-for-object-oriented-c-code/ (retrieved 2026-10-26)

6. Gaps

  • No extern "C" wrapper exists yet - needed only for C/Python FFI; C++ molo links directly.
  • Fully-static link requires static variants of system libs (ssl, crypto, zstd, nghttp2, psl, brotli, idn2, rtmp) present.