This document covers the repository layout, common build/test commands, and the work required to extend TheWatcher end to end.
agent/ Agent runtime, config, enrollment, collectors.
agent/collectors/ CPU, memory, disk, process, network and log collectors.
agent_tests/ Agent config and collector contract tests.
common/ Shared protocol, commands, metrics, crypto, logging, service helpers.
common_tests/ Tests for shared helpers.
dashboard/ React + TypeScript + Vite dashboard.
docs/ Operator and developer documentation.
integration_tests/ End-to-end server-agent lifecycle tests.
plans/ dev-task-planner task plans.
scripts/ Cross-platform build-environment setup scripts.
server/ Server runtime, API, storage, ZAP auth, config.
server_tests/ Store, lifecycle, and ZAP tests.
subprojects/ Meson wrap files and packagefile overlays for libsodium,
libzmq, libcbor, and WrapDB-tracked dependencies.
meson compile -C builddir-release TheWatcherServer TheWatcherAgent
meson test -C builddir-release config_test
meson test -C builddir-release store_test
meson test -C builddir-release status_engine_test
meson test -C builddir-release server_lifecycle_test
meson test -C builddir-release zap_handler_test
meson test -C builddir-release server_agent_integration_test --print-errorlogs
meson test -C builddir-release --print-errorlogsDashboard:
cd dashboard
npm.cmd install
npm.cmd run build
npm.cmd test- C++ code is C++20.
- Format C++ with the repository
.clang-format. CI runsclang-format --dry-run --Werror(version 22.1.5, installable withpip install --only-binary :all: clang-format==22.1.5) over every tracked first-party C++ file (*.cpp,*.hpp,*.houtsidesubprojects/) and fails the build on any difference. Third-party overlays undersubprojects/packagefiles/are not checked. Whole-tree reformatting commits are listed in.git-blame-ignore-revs; rungit config blame.ignoreRevsFile .git-blame-ignore-revsonce sogit blameskips them. - SonarCloud automatic analysis reads
.sonarcloud.properties. Test directories and*.test.ts(x)files are excluded from duplication detection only (BDD scenarios repeat setup deliberately); keep shared setup in helpers when it carries logic. - Keep top-level C++ namespace as
thewatcher. - Prefer structured types in
common/metrics.hpp,common/protocol.hpp, andcommon/commands.hppover ad hoc strings. - Use BDD-style tests with
GIVEN,WHEN, andTHEN. - Add tests before behavior changes.
- Update docs for every behavior or workflow change.
- For security-sensitive changes, update Threat Model with the affected asset, trust boundary, mitigation, and residual risk.
- Bump the
versioninmeson.buildand updateCHANGELOG.mdfor each change set. - Meson builds ZeroMQ and libsodium as local static subprojects from
subprojects/*.wrapplussubprojects/packagefiles/; do not add vcpkg, pkg-config, or system package assumptions for these dependencies. - Keep persistence/status tests on the lighter
server_store_libtarget when they do not need ZeroMQ. Useserver_libonly for tests that exercise the full server runtime. - Keep
httplibroute callbacks self-contained. Shared authorization, session, and command helpers should live onApiServerand callbacks should capturethisor values, not references to stack-local helper lambdas from route setup.
Use this checklist when adding a metric family such as GPU, filesystem inode usage, services, packages, or custom application health.
-
Define the metric shape in
common/metrics.hppandserver/api_json.hpp.In
common/metrics.hpp, add a struct with stable field names, add it toSystemMetrics, and addto_cbor/from_cborspecialisations for the struct. Agents send metrics to the server as CBOR (thecborhelpers live incommon/protocol.hpp), andSystemMetricsis encoded as a fixed-length positional array. Todayfrom_cbor<SystemMetrics>accepts exactly 11 elements and there is no protocol version negotiation. The server decodes agent frames (server/server.cpp) and also re-decodes storedmetrics_cborrows, which are never rewritten (server/api.cpp,server/status_engine.cpp). Changing the exact-length check therefore breaks every existing 11-element frame and stored row. A newSystemMetricsfield must keep decoding the previous layouts: the decoder must reject arrays shorter than the oldest supported length, read the new indices only when present, and default the field otherwise (protocol versioning work in #57 and #102 covers the mechanism). Do not add a field until the decoder does that, or you accept a coordinated upgrade of server and all agents with old stored rows no longer decoding.To add the field itself, in
common/metrics.hpp: (a) into_cbor<SystemMetrics>,pushthe new value (build it first, as the other members are, andrelease()it into the array) at the position you choose and raisecbor_new_definite_array(11)to the new count (this is the length new agents send); (b) infrom_cbor<SystemMetrics>, append the field at the end (inserting in the middle shifts the indices of old frames), and replace thecbor_array_size(item) != 11equality check with a minimum-length check that still accepts every older count, readingarray_get(item, <index>)for the new field only whencbor_array_size(item)is large enough and leaving its default otherwise. The indices must match in both functions. The REST API serialises the same structs as JSON; add theNLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULTmapping for the new struct, and the newSystemMetricsfield, inserver/api_json.hpp. -
Add wire/API compatibility tests.
Update or add tests that round-trip
SystemMetricsthrough CBOR (common_tests/protocol_test.cpp) and check its JSON form. If the new metric affects integration behavior, extendintegration_tests/server_agent_integration_test.cpp. -
Implement the collector.
Add
agent/collectors/<name>_collector.hppand.cpp. Inherit fromthewatcher::agent::Collectorand implement:std::string_view name() const noexcept; void update(SystemMetrics& metrics);
Keep platform-specific code behind preprocessor guards. The agent should still compile on Windows, Linux, and BSD.
-
Register the collector with Meson.
Update
agent/collectors/meson.buildwith the new source and header so the staticagent_collectorslibrary picks them up. -
Add the collector to the agent runtime.
Register it in
Agent::Agent()inagent/agent.cpp. If it needs runtime settings, add those settings tocommon/collector_config.hpp,common/commands.hpp,server/store.hpp,server/store_sqlite.cpp,server/api.cpp,dashboard/src/models.ts, and the Agents Configure modal.ConfigUpdateis the agent-facing carrier for these settings. -
Update dashboard models and status mapping.
Update
dashboard/src/models.tsfor the API shape,dashboard/src/status.tsfor health classification, and the matching file underdashboard/src/pages/ordashboard/src/components/if the UI needs new controls or columns. Collector thresholds should be absolute values in the same units the collector reports: percentages for CPU, memory, and disks; combined megabits per second for network interfaces; exact executable counts for process watches. If the new collector becomes an alerting indicator, also updateserver/status_engine.cppandserver_tests/status_engine_test.cpp. -
Add tests.
Add focused collector tests in
agent_tests/or extendcollector_contract_test.cpp. Add dashboard tests when health classification changes. Extend integration tests when the new metric must be proven through the server API. -
Update docs.
Update Collector Contract, Architecture, Dashboard, and
CHANGELOG.md. -
Run verification.
clang-format -i <changed-cpp-files> meson test -C builddir-release collector_contract_test server_agent_integration_test --print-errorlogs cd dashboard npm.cmd run build npm.cmd test
- Add the command enum and payload struct in
common/commands.hpp. - Add an API route in
server/api.cppthat validates input and queues aCommandMessage. - Handle the command in
Agent::handle_command()inagent/agent.cpp. - If the command changes persistent state, update
server/store.hpp,server/store_sqlite.cpp, the dashboard model, and API tests. - Add BDD tests and update docs.
- Add the persistent or computed field in the server model.
- Serialize it in
agent_to_json()or metric JSON. - Update
dashboard/src/models.ts. - Update
dashboard/src/status.tsor the matching file underdashboard/src/pages/ordashboard/src/components/if displayed. - Run dashboard build/tests and relevant server tests.
Prefer WrapDB-tracked Meson wraps when they preserve behavior. Keep custom packagefile overlays only where the project needs custom build settings (currently libsodium and libzmq, both built with CURVE-enabled static linkage) or the dependency is not available in WrapDB.
Current dependencies pulled in via subprojects/*.wrap:
libzmq(withsubprojects/packagefiles/libzmqoverlay)libsodium(withsubprojects/packagefiles/libsodiumoverlay)libcbor(withsubprojects/packagefiles/libcboroverlay providing pre-generated headers)cppzmq,sqlite3,nlohmann_json,cpp-httplib,catch2-with-main(WrapDB).
- Add or update BDD tests.
- Implement the change.
- Run focused tests.
- Run relevant integration tests.
- Format C++ code.
- Update docs.
- Bump the
versioninmeson.build. - Add a
CHANGELOG.mdentry. - Run final build/test commands for changed components.