11// Black Belt Ethical Auditor - Linux C++17 CLI.
2- // Canonical JSON is forwarded unchanged to the shared AI engine transport.
32#include < cstdlib>
43#include < fstream>
54#include < iostream>
@@ -11,7 +10,7 @@ static void usage(const char* p) {
1110 std::cout << " Usage: " << p << " [--file FILE] [--version] [--help]\n "
1211 << " " << p << " < audit.json\n\n "
1312 << " Black Belt Ethical Auditor Linux CLI (C++17).\n "
14- << " Environment: BBEA_ENGINE_URL, BBEA_MODEL, BBEA_SYSTEM_PROMPT .\n " ;
13+ << " Interactive mode accepts questions or JSON audit objects .\n " ;
1514}
1615
1716static std::string shellQuote (const std::string& s) {
@@ -20,6 +19,20 @@ static std::string shellQuote(const std::string& s) {
2019 return r + " '" ;
2120}
2221
22+ static std::string engineCommand () {
23+ const char * env = std::getenv (" BBEA_ENGINE_CMD" );
24+ if (env && *env) return env;
25+ char exe[4096 ];
26+ ssize_t n = readlink (" /proc/self/exe" , exe, sizeof (exe) - 1 );
27+ if (n > 0 ) {
28+ exe[n] = ' \0 ' ;
29+ std::string path (exe);
30+ auto slash = path.find_last_of (' /' );
31+ if (slash != std::string::npos) return path.substr (0 , slash + 1 ) + " blackbelt-engine.sh" ;
32+ }
33+ return " bin/blackbelt-engine.sh" ;
34+ }
35+
2336static int runEngine (const std::string& input) {
2437 char tmp[] = " /tmp/blackbelt-cpp-XXXXXX" ;
2538 int fd = mkstemp (tmp);
@@ -30,10 +43,7 @@ static int runEngine(const std::string& input) {
3043 perror (" write" ); fclose (fp); unlink (tmp); return 2 ;
3144 }
3245 fclose (fp);
33-
34- const char * env = std::getenv (" BBEA_ENGINE_CMD" );
35- std::string engine = (env && *env) ? env : " bin/blackbelt-engine.sh" ;
36- std::string command = " cat " + shellQuote (tmp) + " | " + shellQuote (engine);
46+ std::string command = " cat " + shellQuote (tmp) + " | " + shellQuote (engineCommand ());
3747 int status = std::system (command.c_str ());
3848 unlink (tmp);
3949 if (status == -1 ) return 3 ;
@@ -42,15 +52,15 @@ static int runEngine(const std::string& input) {
4252
4353static int interactive () {
4454 std::cout << " Black Belt Ethical Auditor\n "
45- << " Enter a JSON audit object, or type 'help' or 'quit'.\n " ;
55+ << " Ask a question or enter a JSON audit object. Type 'help' or 'quit'.\n " ;
4656 std::string line;
4757 for (;;) {
4858 std::cout << " black-belt> " << std::flush;
4959 if (!std::getline (std::cin, line)) break ;
5060 if (line.empty ()) continue ;
5161 if (line == " quit" || line == " exit" ) break ;
5262 if (line == " help" ) {
53- std::cout << " Paste a complete BBEA JSON audit object at the prompt .\n "
63+ std::cout << " Enter a natural-language question or a complete BBEA JSON audit object.\n "
5464 << " Commands: help, quit, exit\n " ;
5565 continue ;
5666 }
@@ -66,23 +76,20 @@ int main(int argc, char** argv) {
6676 for (int i = 1 ; i < argc; ++i) {
6777 std::string a = argv[i];
6878 if (a == " --help" || a == " -h" ) { usage (argv[0 ]); return 0 ; }
69- if (a == " --version" ) { std::cout << " blackbelt-cpp 1.1 (BBEA CLI v2 transport)\n " ; return 0 ; }
79+ if (a == " --version" ) { std::cout << " blackbelt-cpp 1.2 (BBEA CLI v2 transport)\n " ; return 0 ; }
7080 if (a == " --file" && i + 1 < argc) { file = argv[++i]; continue ; }
7181 std::cerr << " Unknown argument: " << a << ' \n ' ; usage (argv[0 ]); return 2 ;
7282 }
73-
7483 if (file.empty () && isatty (STDIN_FILENO )) return interactive ();
75-
7684 std::string input;
77- if (file.empty ()) {
78- input.assign (std::istreambuf_iterator<char >(std::cin), std::istreambuf_iterator<char >());
79- } else {
85+ if (file.empty ()) input.assign (std::istreambuf_iterator<char >(std::cin), std::istreambuf_iterator<char >());
86+ else {
8087 std::ifstream in (file, std::ios::binary);
8188 if (!in) { std::cerr << " Unable to open " << file << ' \n ' ; return 2 ; }
8289 input.assign (std::istreambuf_iterator<char >(in), std::istreambuf_iterator<char >());
8390 }
8491 if (input.find_first_not_of (" \t\r\n " ) == std::string::npos) {
85- std::cerr << " No JSON audit input received.\n " ; return 2 ;
92+ std::cerr << " No audit input received.\n " ; return 2 ;
8693 }
8794 return runEngine (input);
8895}
0 commit comments