From 343e03c27ce9dd668533bb89ccb2c0038cbc6dae Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Thu, 3 Dec 2026 21:42:09 +0300 Subject: [PATCH] feat(daemon): report editor selection and compdb status --- README.md | 2 +- docs/agent-workflow/STATE.md | 4 ++ docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 15 +++++++ docs/roadmap/21-expansion-roadmap.md | 2 +- src/Daemon/Daemon.cpp | 47 ++++++++++++++++++++++ src/Main.cpp | 16 ++++++-- tests/CliContracts.cmake | 1 + tests/DaemonTests.cpp | 58 ++++++++++++++++++++++++++++ 9 files changed, 140 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 55b8213..82e6e9a 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ All CLI help text (`vbs --help`, `vbs --help`, `vbs compdb --help`, `v - `vbs binaries list|fetch --registry URL --name PKG --version X.Y.Z [--variant ID --output FILE] [--token-env VAR]` - `vbs bridge --request FILE --output FILE` (backend for [cmake/bridge/VbsDeps.cmake](cmake/bridge/VbsDeps.cmake)) - `vbs gc [--build-dir DIR] [--max-bytes N]` -- `vbs daemon run|status|stop|gc|recover|describe|build|ide query|ide generate|ide poll|ide wait|compdb export [--project DIR] [--member NAME]` [--build-dir DIR] [--socket PATH]` (Unix-socket daemon holding a warm state store and project watcher; `run` serves in the foreground, the rest are client requests) +- `vbs daemon run|status|stop|gc|recover|describe|build|ide query|ide generate|ide poll|ide wait|ide status|compdb export [--project DIR] [--member NAME]` [--build-dir DIR] [--socket PATH]` (Unix-socket daemon holding a warm state store and project watcher; `run` serves in the foreground, the rest are client requests) - `vbs gen-tests --input FILE --output-dir DIR` - `vbs-registry --data-dir DIR --web-root DIR [--bind ADDR] [--port PORT] ...` diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index f814cfd..77acb90 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -153,6 +153,10 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - Split the daemon build path into `execute_project_build` (returns a structured `BuildOutcome`) and `build_project`; a workspace build without `member` now builds every member in declared order, sharing the root lock and CAS, and returns per-member outcomes plus aggregate `executed`/`cached`/`failed`. A member-scoped build still returns `member`. - The workspace daemon test now expects the workspace-wide build to succeed and include both members, in addition to the member-scoped IDE checks. +- **Wave 34 (Editor Status Protocol Request)**: + - Added the `editor_status` daemon request (`vbs daemon ide status`): reports the active editor selection (`ticket`, profile, build root, generation id, compdb path, root-alias state) plus whether the selected compilation database exists and how many entries it holds. + - Added `Daemon.editor_status_reports_selection_after_compdb_export` (no selection before export, then `debug` selection with a non-empty compdb) and a CLI help contract; Daemon suite is now 14 cases. + ## Remaining future scope - **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, daemon-backed IDE metadata, compdb export, IDE config generation, editor watch poll and bounded long-poll done; dedicated external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 3be96b5..eec4e5a 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -40,4 +40,5 @@ Base HEAD: `fe0d1a6` | Wave 31 (Daemon workspace support) | Workspace `describe` member summaries; workspace `build` with `member` + shared root lock (`DaemonOptions::lock_root`) | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 13/13, full CTest 8/8) | `include/Void/Build/Daemon/Daemon.hpp`, `src/Daemon/Daemon.cpp`, `tests/DaemonTests.cpp`, docs | | Wave 32 (Member-scoped daemon IDE) | `resolve_member_options` shared by daemon IDE query/generate and compdb export; `--member` CLI flags; workspace member IDE coverage | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 13/13, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, docs | | Wave 33 (Daemon workspace-wide build) | `execute_project_build`/`BuildOutcome` split; workspace build without `member` builds all members in order with per-member and aggregate results | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 13/13, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `tests/DaemonTests.cpp`, docs | +| Wave 34 (Editor status request) | `editor_status` daemon request + `vbs daemon ide status`: selection state, compdb existence/entry count | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 14/14, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 46a91b5..258d1c7 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -598,6 +598,21 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - Full CTest: **8 / 8 passed** in 211.82 s. - `clang-format --dry-run --Werror` passes on the changed C++ files. +## Editor Status Protocol Request (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_v1_tests --suite Daemon --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Daemon suite: **14 / 14 passed** in 28.76 s, including + `editor_status_reports_selection_after_compdb_export`: before export the selection is null and + `compdb_exists=false`; after `compdb_export`, `editor_status` reports profile `debug`, an + existing compdb with `compdb_entries >= 1`, and a non-empty compdb path. +- Full CTest: **8 / 8 passed** in 216.37 s. +- `clang-format --dry-run --Werror` passes on the changed C++ files. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/21-expansion-roadmap.md b/docs/roadmap/21-expansion-roadmap.md index 14abb35..e96c22e 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -73,7 +73,7 @@ flowchart LR | --- | --- | --- | | **E1 — Everyday CLI Ergonomics (Implemented in Wave 8)** | `vbs init` project scaffolding, `vbs clean`, `vbs doctor` environment diagnostics, `vbs graph --format dot|json`, and `vbs build --native-foreign`. | End-to-end CLI & integration tests passing in `vbs_cli_contract` and `vbs_v1_tests`. | | **E2 — Multi-Package Workspaces (`workspace.cpp`)** *(verified in Docker GCC 16)* | Shared root `vbs.lock` and `build/.vbs` CAS, `workspace_dependency()` cross-member native linking, and affected-member selection (`vbs build/test --member ` / `--changed-since `). | 3-package workspace fixture (shared library + app + tests) builds/tests with one root lockfile; member selection and `--changed-since` verified in `FullV1Tests.workspace_members_shared_build_and_member_selection`. | -| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), and `vbs daemon ide wait` adds a bounded long-poll variant. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | +| **E3 — IDE Config/Query & Background Daemon** | `build.cpp`/`build.profiles.cpp`/`build-support/` SDK entries in `compile_commands.json` + `vbs ide generate` (`.clangd`, `.vscode/`, `.zed/`, `.idea/customTargets.xml`) & `vbs ide query` (**Implemented & Verified in Wave 10**); Unix-socket daemon core holding a warm `StateStore` + project `DirectoryWatcher` with `vbs daemon run\|status\|stop\|gc\|recover\|describe` (**Implemented & Verified in Wave 14; bounded `describe` added in the post-v1 daemon follow-up**). `describe` returns a bounded graph summary (`target_names` ≤ 128 entries × 200 bytes, `profile` ≤ 128 bytes, 10 s evaluation timeout); `vbs daemon build` executes the lowered graph in-process against the warm state store with bounded `profile`/`targets`/`jobs`, including daemon-side dependency resolution/materialization and provider import via `Package::resolve_and_materialize_dependencies`; `vbs daemon ide query` publishes/selects the profile compilation database and serves the IDE workspace/target metadata JSON over the socket, `vbs daemon compdb export` returns the published compilation-database path and entry count, `vbs daemon ide generate` writes the editor presets over the socket, `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state), `vbs daemon ide wait` adds a bounded long-poll variant, and `vbs daemon ide status` reports the active editor selection and compdb state. Daemon workspace support describes members, builds all members in order (or a selected member) with the shared root lock, and serves member-scoped IDE query/generate/compdb requests via `--member`. Dedicated editor extensions remain planned. | `vbs ide` & `build.cpp` syntax-check verified in `FullV1Tests.cpp`; daemon lifecycle/status/gc/shutdown/describe verified in `DaemonTests.cpp` (6/6 under `dev cpp-gcc`); the live `vbs daemon describe` CLI round-trip is verified in `vbs_cli_contract`. | | **E4 — Transport & Storage Upstream Alignment** | Adopt `Void::Net` (`VL-004`/`VL-005`) and `Void::Sqlite` (`VL-011b`) when lightweight/bundled builds become available in minimal Nix toolchains, reducing VBS transport code further. | All `vbs_registry_tests` and `vbs_core_tests` pass on both minimal and full toolchains. | --- diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 2f5242b..9fb4f83 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -809,6 +810,49 @@ std::string compdb_export_project(const DaemonOptions &options, std::string_view return serialize_response(JsonValue{std::move(object)}); } +// Reports the active editor selection and the published compilation database state. +std::string editor_status_project(const DaemonOptions &options) { + auto selection = Editor::read_selection_state(options.project_root); + if (!selection) { + return error_response(std::format("editor_status: {}", selection.error().format())); + } + + JsonValue::Object object; + object.emplace("ok", JsonValue{true}); + object.emplace("op", JsonValue{std::string{"editor_status"}}); + if (!selection->has_value()) { + object.emplace("selection", JsonValue{nullptr}); + object.emplace("compdb_exists", JsonValue{false}); + return serialize_response(JsonValue{std::move(object)}); + } + + const auto &state = **selection; + JsonValue::Object selected; + selected.emplace("ticket", JsonValue{static_cast(state.ticket)}); + selected.emplace("profile", JsonValue{state.selected_profile}); + selected.emplace("build_root", JsonValue{state.selected_build_root.string()}); + selected.emplace("generation_id", JsonValue{state.selected_generation_id}); + selected.emplace("compdb_path", JsonValue{state.selected_compdb_path.string()}); + selected.emplace("alias_active", JsonValue{state.managed_root_alias_active}); + selected.emplace("alias_warning", JsonValue{state.root_alias_warning}); + object.emplace("selection", JsonValue{std::move(selected)}); + + std::ifstream compdb{state.selected_compdb_path}; + const bool compdb_exists = compdb.good(); + object.emplace("compdb_exists", JsonValue{compdb_exists}); + if (compdb_exists) { + std::string text{std::istreambuf_iterator{compdb}, std::istreambuf_iterator{}}; + auto parsed = Void::Json::Strict::parse(text); + if (parsed) { + if (const auto *array = std::get_if(&parsed->value)) { + object.emplace("compdb_entries", + JsonValue{static_cast(array->size())}); + } + } + } + return serialize_response(JsonValue{std::move(object)}); +} + // Publishes the compilation database and writes the requested editor configuration files. std::string ide_generate_project(const DaemonOptions &options, std::string_view profile_name, std::optional compiler_override, @@ -1132,6 +1176,9 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view object.emplace("rescan_required", JsonValue{batch->rescan_required}); return {serialize_response(JsonValue{std::move(object)}), false}; } + if (*name == "editor_status") { + return {editor_status_project(options), false}; + } if (*name == "watch_wait") { std::int64_t timeout_ms = kDefaultWatchWaitMs; if (const auto entry = object->find("timeout_ms"); entry != object->end()) { diff --git a/src/Main.cpp b/src/Main.cpp index cd67e40..78477a5 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1551,6 +1551,8 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { } request_json = std::format(R"({{"op":"describe","profile":{}}})", Util::json_quote(opts.profile_arg)); + } else if (sub == "editor_status") { + request_json = R"({"op":"editor_status"})"; } else if (sub == "watch_poll") { request_json = R"({"op":"watch_poll"})"; } else if (sub == "watch_wait") { @@ -1618,10 +1620,10 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) { // Describe evaluates the whole project graph (descriptor compile, toolchain probe, lowering), // which can exceed the 2 s default; the daemon bounds evaluation at 10 s. const auto request_timeout = - sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}} - : sub == "watch_poll" ? std::chrono::milliseconds{5000} - : sub == "watch_wait" ? std::chrono::milliseconds{10000} - : sub == "describe" ? std::chrono::milliseconds{15000} + sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}} + : (sub == "watch_poll" || sub == "editor_status") ? std::chrono::milliseconds{5000} + : sub == "watch_wait" ? std::chrono::milliseconds{10000} + : sub == "describe" ? std::chrono::milliseconds{15000} : (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export") ? std::chrono::milliseconds{30000} : std::chrono::milliseconds{2000}; @@ -2621,6 +2623,9 @@ int main(int argc, char **argv) { .option_default("--profile", "-p", "Profile to query", daemon_opts.profile_arg, "debug") .option("--member", "", "Workspace member (required for workspace roots)", daemon_opts.member_arg); + auto &daemon_ide_status_cmd = + daemon_ide_cmd.subcommand("status", "Report the active editor selection and compdb state"); + configure_daemon_common(daemon_ide_status_cmd); auto &daemon_ide_poll_cmd = daemon_ide_cmd.subcommand( "poll", "Poll pending project file changes (editor extension protocol)"); configure_daemon_common(daemon_ide_poll_cmd); @@ -2744,6 +2749,9 @@ int main(int argc, char **argv) { } else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 && parsed.matched_command_path[2] == "generate") { daemon_sub = "ide_generate"; + } else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 && + parsed.matched_command_path[2] == "status") { + daemon_sub = "editor_status"; } else if (daemon_sub == "ide" && parsed.matched_command_path.size() > 2 && parsed.matched_command_path[2] == "poll") { daemon_sub = "watch_poll"; diff --git a/tests/CliContracts.cmake b/tests/CliContracts.cmake index 59fcaa2..9d9445c 100644 --- a/tests/CliContracts.cmake +++ b/tests/CliContracts.cmake @@ -60,6 +60,7 @@ check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query -- check_process(0 "Usage: vbs daemon compdb export .*--profile" "" daemon compdb export --help) check_process(0 "Usage: vbs daemon ide generate .*--profile.*--editor.*--force" "" daemon ide generate --help) check_process(0 "Usage: vbs daemon ide poll " "" daemon ide poll --help) +check_process(0 "Usage: vbs daemon ide status " "" daemon ide status --help) check_process(0 "Usage: vbs daemon ide wait .*--timeout-ms" "" daemon ide wait --help) check_process(2 "" "missing subcommand for 'vbs daemon'" daemon) diff --git a/tests/DaemonTests.cpp b/tests/DaemonTests.cpp index 8db8e7c..8ef3d84 100644 --- a/tests/DaemonTests.cpp +++ b/tests/DaemonTests.cpp @@ -679,6 +679,64 @@ VOID_TEST(Daemon, watch_wait_long_polls_until_change_and_times_out) { Void::Testing::expect(run_result.has_value()); } +VOID_TEST(Daemon, editor_status_reports_selection_after_compdb_export) { + auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); + Void::Testing::require(temp.has_value()); + const auto options = make_options(temp->path()); + + { + std::ofstream descriptor{options.project_root / "build.cpp"}; + descriptor << R"cpp(#include + +void build(Void::Build::Project &project) { + auto app = project.executable("app"); + app.sources({"main.cpp"}); +} +)cpp"; + Void::Testing::require(descriptor.good()); + } + { + std::ofstream source{options.project_root / "main.cpp"}; + source << "int main() { return 0; }\n"; + Void::Testing::require(source.good()); + } + + auto server = Void::Build::Daemon::DaemonServer::create(options); + Void::Testing::require(server.has_value()); + const auto socket = server->socket_path(); + + Void::Result::Result run_result; + std::jthread worker{[&] { run_result = server->run(); }}; + Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5})); + + auto empty = request_object(socket, R"({"op":"editor_status"})"); + Void::Testing::require(empty.has_value()); + Void::Testing::expect(bool_field(*empty, "ok")); + Void::Testing::expect(field(*empty, "selection") != nullptr); + Void::Testing::expect(!bool_field(*empty, "compdb_exists", true)); + + auto exported = request_object(socket, R"({"op":"compdb_export"})", std::chrono::seconds{120}); + Void::Testing::require(exported.has_value()); + Void::Testing::expect(bool_field(*exported, "ok")); + + auto status = request_object(socket, R"({"op":"editor_status"})"); + Void::Testing::require(status.has_value()); + Void::Testing::expect(bool_field(*status, "ok")); + Void::Testing::expect(bool_field(*status, "compdb_exists")); + Void::Testing::expect(int_field(*status, "compdb_entries") >= 1); + const auto *selection = field(*status, "selection"); + Void::Testing::require(selection != nullptr); + const auto *selection_object = as_object(*selection); + Void::Testing::require(selection_object != nullptr); + Void::Testing::expect_eq(str_field(*selection_object, "profile"), std::string{"debug"}); + Void::Testing::expect(!str_field(*selection_object, "compdb_path").empty()); + + auto shutdown = Void::Build::Daemon::request(socket, R"({"op":"shutdown"})"); + Void::Testing::expect(shutdown.has_value()); + worker.join(); + Void::Testing::expect(run_result.has_value()); +} + VOID_TEST(Daemon, describe_empty_project_reports_zero_targets) { auto temp = Void::FileSystem::TempDir::open("vbs_daemon_"); Void::Testing::require(temp.has_value());