Skip to content

Commit f587984

Browse files
committed
feat(cli): add websocket command and improve runtime diagnostics
1 parent d1b012c commit f587984

53 files changed

Lines changed: 7833 additions & 448 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ else()
152152
set(_VIX_SYNC_DIR "${_VIX_MODULES_DIR}/sync")
153153
set(_VIX_CACHE_DIR "${_VIX_MODULES_DIR}/cache")
154154
set(_VIX_AGENT_DIR "${_VIX_MODULES_DIR}/agent")
155+
set(_VIX_WEBSOCKET_DIR "${_VIX_MODULES_DIR}/websocket")
155156

156157
set(_LOCAL_LAYOUT_OK FALSE)
157158
if (EXISTS "${_VIX_CORE_DIR}/CMakeLists.txt" AND EXISTS "${_VIX_UTILS_DIR}/CMakeLists.txt")
@@ -205,6 +206,11 @@ else()
205206
add_subdirectory("${_VIX_AGENT_DIR}" "${CMAKE_BINARY_DIR}/_vix_ai_agent")
206207
endif()
207208

209+
if (EXISTS "${_VIX_WEBSOCKET_DIR}/CMakeLists.txt" AND NOT TARGET vix::websocket)
210+
set(VIX_WEBSOCKET_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
211+
add_subdirectory("${_VIX_WEBSOCKET_DIR}" "${CMAKE_BINARY_DIR}/_vix_websocket")
212+
endif()
213+
208214
if (EXISTS "${_VIX_P2P_DIR}/CMakeLists.txt" AND NOT TARGET vix::p2p)
209215
add_subdirectory("${_VIX_P2P_DIR}" "${CMAKE_BINARY_DIR}/_vix_p2p")
210216
endif()
@@ -253,6 +259,10 @@ else()
253259
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::ai_agent)
254260
endif()
255261

262+
if (TARGET vix::websocket)
263+
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::websocket)
264+
endif()
265+
256266
if (TARGET vix::p2p)
257267
list(APPEND _VIX_LOCAL_LINK_TARGETS vix::p2p)
258268
endif()
@@ -269,6 +279,7 @@ else()
269279
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_SYNC_DIR}/include")
270280
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_CACHE_DIR}/include")
271281
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_AGENT_DIR}/include")
282+
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_WEBSOCKET_DIR}/include")
272283
vix_append_if_exists(_VIX_LOCAL_INCLUDE_DIRS "${_VIX_P2P_DIR}/include")
273284

274285
if (_VIX_LOCAL_LINK_TARGETS)
@@ -330,6 +341,17 @@ else()
330341
message(STATUS "[cli] Game command disabled: vix::game target not found")
331342
endif()
332343

344+
# ----------------------------------------------------
345+
# Optional websocket command support
346+
# ----------------------------------------------------
347+
if (TARGET vix::websocket)
348+
message(STATUS "[cli] WebSocket command enabled")
349+
target_link_libraries(vix_cli PRIVATE vix::websocket)
350+
target_compile_definitions(vix_cli PRIVATE VIX_CLI_HAS_WEBSOCKET=1)
351+
else()
352+
message(STATUS "[cli] WebSocket command disabled: vix::websocket target not found")
353+
endif()
354+
333355
if (TARGET vix_warnings)
334356
target_link_libraries(vix_cli PRIVATE vix_warnings)
335357
endif()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
*
3+
* @file WsCommand.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_WS_COMMAND_HPP
14+
#define VIX_WS_COMMAND_HPP
15+
16+
#include <string>
17+
#include <vector>
18+
19+
namespace vix::commands
20+
{
21+
/**
22+
* @brief Command entry point for WebSocket production diagnostics.
23+
*/
24+
struct WsCommand
25+
{
26+
/**
27+
* @brief Run the ws command.
28+
*
29+
* Supported forms:
30+
*
31+
* `vix ws check`
32+
* `vix ws check ws://127.0.0.1:9090/ws`
33+
*
34+
* Options:
35+
*
36+
* `--timeout <ms>`
37+
* `--no-ping`
38+
* `--verbose`
39+
*
40+
* @param args Command arguments after `ws`.
41+
* @return Process exit code.
42+
*/
43+
static int run(const std::vector<std::string> &args);
44+
45+
/**
46+
* @brief Print ws command help.
47+
*
48+
* @return Process exit code.
49+
*/
50+
static int help();
51+
};
52+
}
53+
54+
#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
*
3+
* @file WsChecker.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_WS_CHECKER_HPP
14+
#define VIX_WS_CHECKER_HPP
15+
16+
#include <vix/cli/commands/ws/WsTypes.hpp>
17+
18+
namespace vix::commands::ws::checker
19+
{
20+
/**
21+
* @brief Check a WebSocket endpoint.
22+
*
23+
* The checker validates the URL, extracts host/port/path, attempts a native
24+
* WebSocket connection and reports handshake/connectivity diagnostics.
25+
*
26+
* @param cfg Effective WebSocket configuration.
27+
* @param options Runtime WebSocket options.
28+
* @return Process exit code.
29+
*/
30+
int check(
31+
const WsConfig &cfg,
32+
const WsOptions &options);
33+
}
34+
35+
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
*
3+
* @file WsConfig.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_WS_CONFIG_HPP
14+
#define VIX_WS_CONFIG_HPP
15+
16+
#include <vix/cli/commands/ws/WsTypes.hpp>
17+
18+
#include <optional>
19+
#include <string>
20+
21+
namespace vix::commands::ws
22+
{
23+
/**
24+
* @brief Read the current Vix project name.
25+
*
26+
* The project name is resolved from `vix.json` when available.
27+
* If no project name is found, the implementation may fall back to
28+
* the current directory name.
29+
*
30+
* @return The detected project name, or std::nullopt if no name can be resolved.
31+
*/
32+
std::optional<std::string> read_project_name();
33+
34+
/**
35+
* @brief Load production WebSocket configuration from vix.json.
36+
*
37+
* The configuration is read from:
38+
* - `production.websocket`
39+
* - `production.proxy.websocket`
40+
* - core `websocket.*` values when available
41+
*
42+
* @return Loaded WebSocket configuration.
43+
*/
44+
WsConfig load_ws_config();
45+
46+
/**
47+
* @brief Apply command-line ws options to the loaded config.
48+
*
49+
* @param cfg Loaded WebSocket configuration.
50+
* @param options Runtime ws options.
51+
* @return Effective WebSocket configuration.
52+
*/
53+
WsConfig apply_ws_options(
54+
WsConfig cfg,
55+
const WsOptions &options);
56+
}
57+
58+
#endif
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
*
3+
* @file WsOutput.hpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2026, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
12+
*/
13+
#ifndef VIX_WS_OUTPUT_HPP
14+
#define VIX_WS_OUTPUT_HPP
15+
16+
#include <vix/cli/commands/ws/WsTypes.hpp>
17+
18+
#include <iosfwd>
19+
#include <string>
20+
21+
namespace vix::commands::ws::output
22+
{
23+
/**
24+
* @brief Print the WebSocket check summary.
25+
*
26+
* @param out Output stream.
27+
* @param cfg Effective WebSocket configuration.
28+
* @param options Runtime WebSocket options.
29+
*/
30+
void print_summary(
31+
std::ostream &out,
32+
const WsConfig &cfg,
33+
const WsOptions &options);
34+
35+
/**
36+
* @brief Print the beginning of a WebSocket step.
37+
*
38+
* @param out Output stream.
39+
* @param label Step label.
40+
*/
41+
void step(
42+
std::ostream &out,
43+
const std::string &label);
44+
45+
/**
46+
* @brief Print a key/value command line.
47+
*
48+
* @param out Output stream.
49+
* @param command Command text.
50+
*/
51+
void command(
52+
std::ostream &out,
53+
const std::string &command);
54+
55+
/**
56+
* @brief Print a successful WebSocket operation message.
57+
*
58+
* @param out Output stream.
59+
* @param message Message to print.
60+
*/
61+
void ok(
62+
std::ostream &out,
63+
const std::string &message);
64+
65+
/**
66+
* @brief Print a WebSocket warning message.
67+
*
68+
* @param out Output stream.
69+
* @param message Message to print.
70+
*/
71+
void warn(
72+
std::ostream &out,
73+
const std::string &message);
74+
75+
/**
76+
* @brief Print a WebSocket error message.
77+
*
78+
* @param out Output stream.
79+
* @param message Message to print.
80+
*/
81+
void error(
82+
std::ostream &out,
83+
const std::string &message);
84+
85+
/**
86+
* @brief Print a fix suggestion.
87+
*
88+
* @param out Output stream.
89+
* @param message Fix suggestion.
90+
*/
91+
void fix(
92+
std::ostream &out,
93+
const std::string &message);
94+
}
95+
96+
#endif

0 commit comments

Comments
 (0)