From 3f1410a0951b984c239945de046b48188f373baf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=CE=A7=CE=B3=CF=86=CF=84=20Kompanion?=
 <chigammaphitau@chelydra.at>
Date: Sun, 19 Oct 2025 19:13:25 +0200
Subject: [PATCH] Fix compile of command line parser

This is such an antiattren, amazing.
---
 src/cli/CMakeLists.txt   |  1 +
 src/cli/KompanionApp.cpp | 54 ++++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt
index 9148878..c785a2d 100644
--- a/src/cli/CMakeLists.txt
+++ b/src/cli/CMakeLists.txt
@@ -7,6 +7,7 @@ Qt6::Core
 Qt6::Sql
 KF6::ConfigCore
 kom_dal
+kompanion_mw
 kom_ki
 kom_mcp
 Qt6::McpServer
diff --git a/src/cli/KompanionApp.cpp b/src/cli/KompanionApp.cpp
index 858642c..954cd20 100644
--- a/src/cli/KompanionApp.cpp
+++ b/src/cli/KompanionApp.cpp
@@ -841,64 +841,58 @@ int main(int argc, char** argv) {
   parser.addOption(mcpAddrOption);
 
   // DB navigation helpers
-  QCommandLineOption dbNsOption(QStringList() << "--db-namespaces",
+  QCommandLineOption dbNsOption(QStringList() << "db-namespaces",
                                 "List namespaces in the database and exit.");
   parser.addOption(dbNsOption);
-  QCommandLineOption dbItemsOption(QStringList() << "--db-items",
+  QCommandLineOption dbItemsOption(QStringList() << "db-items",
                                    "List recent items in a namespace (requires --ns). Optional --limit.");
   parser.addOption(dbItemsOption);
-  QCommandLineOption nsNameOption(QStringList() << "--ns",
+  QCommandLineOption nsNameOption(QStringList() << "ns",
                                   "Namespace name for DB operations.",
                                   "name");
   parser.addOption(nsNameOption);
-  QCommandLineOption limitOption(QStringList() << "--limit",
+  QCommandLineOption limitOption(QStringList() << "limit",
                                  "Limit for DB operations (default 10).",
                                  "n", "10");
   parser.addOption(limitOption);
-  QCommandLineOption dbSearchOption(QStringList() << "--db-search",
+  QCommandLineOption queryOption(QStringList() << "db-search",
                                     "Hybrid search in a namespace. Use --text and/or --embedding-file. Requires --ns.");
-  parser.addOption(dbSearchOption);
-  QCommandLineOption textOption(QStringList() << "--text",
-                                "Text query for DB search.",
-                                "q");
-  parser.addOption(textOption);
-  QCommandLineOption embFileOption(QStringList() << "--embedding-file",
+  parser.addOption(queryOption);
+  QCommandLineOption  embFileOption(QStringList() << "embedding-file",
                                    "Path to JSON array containing embedding vector for hybrid search.",
                                    "path");
   parser.addOption(embFileOption);
 
   // Snapshot helpers
-  QCommandLineOption snapshotSaveOption(QStringList() << "--snapshot-save",
+  QCommandLineOption snapshotSaveOption(QStringList() << "snapshot-save",
                                         "Save a JSON snapshot (content) under a key in --ns. Provide content via -r/--stdin/[payload].");
   parser.addOption(snapshotSaveOption);
-  QCommandLineOption snapshotLoadOption(QStringList() << "--snapshot-load",
+  QCommandLineOption snapshotLoadOption(QStringList() << "snapshot-load",
                                         "Load a JSON snapshot for --ns and --key and print it.");
   parser.addOption(snapshotLoadOption);
-  QCommandLineOption keyOption(QStringList() << "--key",
+  QCommandLineOption keyOption(QStringList() << "key",
                                "Key for snapshot operations (default 'session:last').",
                                "key", "session:last");
   parser.addOption(keyOption);
 
   // Warm cache + rehydrate helpers
-  QCommandLineOption warmCacheOption(QStringList() << "--warm-cache",
+  QCommandLineOption warmCacheOption(QStringList() << "warm-cache",
                                      "Warm precomputed embeddings (policy or ad-hoc). Use with --policy or --id.");
   parser.addOption(warmCacheOption);
-  QCommandLineOption policyOption(QStringList() << "--policy",
+  QCommandLineOption policyOption(QStringList() << "policy",
                                   "Policy file (YAML/JSON) describing namespaces, model, limit, window_days.",
                                   "path");
   parser.addOption(policyOption);
-  QCommandLineOption idOption(QStringList() << "--id",
+  QCommandLineOption idOption(QStringList() << "id",
                               "Explicit item id for ad-hoc warm cache (use with --stdin or -r).",
                               "id");
   parser.addOption(idOption);
+
+  parser.addOption(idOption);
   QCommandLineOption rehydrateOption(QStringList() << "--rehydrate",
                                      "Compose a rehydration frame: snapshot + top-K search for --text.");
   parser.addOption(rehydrateOption);
-  QCommandLineOption textQOption(QStringList() << "--text",
-                                 "Text query for rehydrate/search.",
-                                 "q");
-  parser.addOption(textQOption);
-  QCommandLineOption kOption(QStringList() << "-k",
+  QCommandLineOption kOption(QStringList() << "k",
                              "Top-K for rehydrate/search.",
                              "k", "8");
   parser.addOption(kOption);
@@ -975,8 +969,8 @@ int main(int argc, char** argv) {
   // Snapshot helpers (exclusive)
   if (snapSave || snapLoad) {
     const QString ns = parser.value(nsNameOption);
+    const QString nsQuery = parser.value(nsQuery);
     if (ns.isEmpty()) { qerr << "--snapshot-save/load requires --ns <name>\n"; return 1; }
-    const QString key = parser.value(keyOption);
     if (snapSave) {
       // Resolve content from CLI
       std::string raw;
@@ -987,13 +981,13 @@ int main(int argc, char** argv) {
       }
       // Wrap into save_context call
       std::ostringstream req;
-      req << "{\"namespace\":\"" << ns.toStdString() << "\",\"key\":\"" << key.toStdString() << "\",\"content\":" << raw << ",\"tags\":[\"snapshot\"]}";
+      req << "{\"namespace\":\"" << ns.toStdString() << "\",\"key\":\"" << nsQuery.toStdString() <<  "\",\"content\":" << raw << ",\"tags\":[\"snapshot\"]}";
       const std::string out = server.dispatch("kom.memory.v1.save_context", req.str());
       std::cout << out << std::endl;
       return 0;
     } else {
       std::ostringstream req;
-      req << "{\"namespace\":\"" << ns.toStdString() << "\",\"key\":\"" << key.toStdString() << "\"}";
+      req << "{\"namespace\":\"" << ns.toStdString() << "\",\"key\":\"" << nsQuery.toStdString() << "\"}";
       const std::string out = server.dispatch("kom.memory.v1.recall_context", req.str());
       std::cout << out << std::endl;
       return 0;
@@ -1070,13 +1064,13 @@ int main(int argc, char** argv) {
   if (rehydrate) {
     const QString ns = parser.value(nsNameOption);
     const QString key = parser.value(keyOption);
-    const QString text = parser.value(textQOption);
+    const QString text = parser.value(queryOption);
     bool ok=false; int k = parser.value(kOption).toInt(&ok); if (!ok || k<=0) k=8;
     // Recall snapshot
     std::ostringstream r1; r1 << "{\"namespace\":\"" << ns.toStdString() << "\",\"key\":\"" << key.toStdString() << "\"}";
     const std::string snapshot = server.dispatch("kom.memory.v1.recall_context", r1.str());
     // Search
-    std::ostringstream r2; r2 << "{\"namespace\":\"" << ns.toStdString() << "\",\"query\":{\"text\":\"" << detail::json_escape(text.toStdString()) << "\",\"k\":" << k << "}}";
+    std::ostringstream r2; r2 << "{\"namespace\":\"" << ns.toStdString() << "\",\"query\":{\"text\":\"" << jsonEscape(text) << "\",\"k\":" << k << "}}";
     const std::string matches = server.dispatch("kom.memory.v1.search_memory", r2.str());
     // Compose
     std::cout << "{\"snapshot\":" << snapshot << ",\"search\":" << matches << "}" << std::endl;
@@ -1093,11 +1087,11 @@ int main(int argc, char** argv) {
     bool ok=false; int lim = parser.value(limitOption).toInt(&ok); if (!ok || lim<=0) lim=10;
     return dbListItems(ns, lim, qout) ? 0 : 1;
   }
-  if (parser.isSet(dbSearchOption)) {
-    const QString ns = parser.value(nsNameOption);
+  if (parser.isSet(queryOption)) {
+    const QString ns = parser.value(queryOption);
     if (ns.isEmpty()) { qerr << "--db-search requires --ns <name>\n"; return 1; }
     bool ok=false; int k = parser.value(limitOption).toInt(&ok); if (!ok || k<=0) k=5;
-    const QString text = parser.value(textOption);
+    const QString text = parser.value(queryOption);
     const QString embPath = parser.value(embFileOption);
     return dbSearch(ns, text, embPath, k, qout) ? 0 : 1;
   }
