Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic_audit.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
13#include "engine_handle.h"
14
15#include <entropic/entropic.h>
18#include "json_serializers.h"
19#include <fstream>
20#include <string>
21
22static auto logger = entropic::log::get("facade.audit");
23
32extern "C" ENTROPIC_EXPORT entropic_error_t
34 if (!handle) { return ENTROPIC_ERROR_INVALID_HANDLE; }
35 if (!handle->audit_logger) { return ENTROPIC_OK; }
36 handle->audit_logger->flush();
37 return ENTROPIC_OK;
38}
39
48extern "C" ENTROPIC_EXPORT entropic_error_t
50 if (!handle || !count) {
51 return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
53 }
54 *count = handle->audit_logger
55 ? handle->audit_logger->entry_count() : 0;
56 return ENTROPIC_OK;
57}
58
71extern "C" ENTROPIC_EXPORT entropic_error_t
73 entropic_handle_t handle,
74 const char* path,
75 const char* /*filter_json*/,
76 char** result_json) {
77 if (!handle || !path || !result_json) {
78 return !handle ? ENTROPIC_ERROR_INVALID_HANDLE
80 }
81 try {
82 std::ifstream file(path);
83 if (!file.is_open()) { throw std::runtime_error("cannot open"); }
84 nlohmann::json arr = nlohmann::json::array();
85 std::string line;
86 while (std::getline(file, line)) {
87 if (line.empty()) { continue; }
88 // Issue #3 (v2.1.1): inbound boundary from disk. Audit files
89 // written by pre-2.1.1 engine versions (or by future writers
90 // that miss a sanitize step) may contain bytes that parse
91 // fine but throw on the arr.dump() below. Sanitize before
92 // ingestion so the dump cannot fail. See
93 // include/entropic/mcp/utf8_sanitize.h for the boundary policy.
94 arr.push_back(nlohmann::json::parse(
95 entropic::mcp::sanitize_utf8(line)));
96 }
97 *result_json = strdup(arr.dump().c_str());
98 return ENTROPIC_OK;
99 } catch (const std::exception& e) {
100 handle->last_error = e.what();
101 return ENTROPIC_ERROR_IO;
102 }
103}
Private definition of the entropic_engine struct.
Public C API for the Entropic inference engine.
ENTROPIC_EXPORT entropic_error_t entropic_audit_flush(entropic_handle_t handle)
Flush the audit logger to disk.
ENTROPIC_EXPORT entropic_error_t entropic_audit_read(entropic_handle_t handle, const char *path, const char *, char **result_json)
Read audit log entries from a JSONL file.
ENTROPIC_EXPORT entropic_error_t entropic_audit_count(entropic_handle_t handle, size_t *count)
Get the number of audit log entries this session.
entropic_error_t
Error codes returned by all C API functions.
Definition error.h:37
@ ENTROPIC_OK
Success.
Definition error.h:38
@ ENTROPIC_ERROR_INVALID_ARGUMENT
NULL pointer, empty string, out-of-range value.
Definition error.h:39
@ ENTROPIC_ERROR_INVALID_HANDLE
NULL or destroyed handle (v1.8.9)
Definition error.h:57
@ ENTROPIC_ERROR_IO
File/network I/O error.
Definition error.h:52
JSON serialization helpers for the facade.
spdlog initialization and logger access.
ENTROPIC_EXPORT std::shared_ptr< spdlog::logger > get(const std::string &name)
Get or create a named logger.
Definition logging.cpp:211
Engine handle struct — owns all subsystems.
std::unique_ptr< entropic::AuditLogger > audit_logger
Audit log.
std::string last_error
Per-handle error message.
UTF-8 validation + replacement at every system boundary where bytes change ownership.