feat(daemon): add editor-extension watch poll protocol
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 7s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 1m19s

This commit is contained in:
faumaray committed 2026-12-03 20:45:09 +03:00
1 parent e15e2cb2b4
commit c7a6bad3c0
9 files changed
+122 -14

No files matched your search

+1 -1
View File
@@ -105,7 +105,7 @@ All CLI help text (`vbs --help`, `vbs <command> --help`, `vbs compdb --help`, `v
- `vbs publish --registry URL --name PKG --version X.Y.Z [--project DIR] [--description TEXT] [--token-env VAR] [--private]`
- `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|compdb export [--project DIR] [--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|compdb export [--project DIR] [--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] ...`
+5 -1
View File
@@ -120,9 +120,13 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B
- Added the `ide_generate` daemon request (`vbs daemon ide generate [--profile] [--editor] [--force]`): it lowers the graph, publishes the compilation database, writes the requested editor presets (`.clangd`, `.vscode/`, `.zed/`, `.idea/`), and returns `ok`/`op=ide_generate`/`profile`/`editor` with `written` and `skipped` file lists.
- Added `Daemon.ide_generate_writes_editor_configs` (invalid editor rejected; `.clangd` written) and a CLI help contract; Daemon suite is now 11 cases.
- **Wave 26 (Track E3 Editor-Extension Watch Protocol)**:
- Added the `watch_poll` daemon request (`vbs daemon ide poll`): it drains the warm inotify watcher, buffers changed paths (bounded to 4096, shared with the daemon loop so events are never lost between requests), and returns `sequence`, `watch_events`, `changed`, `overflowed`, and `rescan_required` for editor extensions.
- Added `Daemon.watch_poll_reports_changed_paths` (a newly created file is observed through repeated polls) and a CLI help contract; Daemon suite is now 12 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 and IDE config generation done; dedicated external editor extensions remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned 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 and the editor watch-poll protocol done; dedicated external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope.
## Environment notes & upstream boundaries
+1
View File
@@ -32,4 +32,5 @@ Base HEAD: `fe0d1a6`
| Wave 23 (Track C1 watcher split) | Move the Linux inotify watcher to `src/Watch/Linux/Watcher.cpp` with an explicit non-Linux boundary; update source lists/docs | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; full CTest 8/8) | `src/Watch/Linux/Watcher.cpp`, `CMakeLists.txt`, `build.cpp`, `recipes/SelfHost/VbsSelfHostRecipe.cpp`, docs |
| Wave 24 (Track E3 daemon compdb export) | `compdb_export` daemon request + `vbs daemon compdb export` CLI: lowers the graph, publishes/selects the profile compdb, returns path/entry count | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 10/10, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs |
| Wave 25 (Track E3 daemon IDE generate) | `ide_generate` daemon request + `vbs daemon ide generate` CLI: lowers the graph, publishes compdb, writes editor presets, returns written/skipped lists | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 11/11, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs |
| Wave 26 (Track E3 editor watch protocol) | `watch_poll` daemon request + `vbs daemon ide poll`: drains the warm watcher, buffers bounded changed paths, returns sequence/events/changed/overflow state | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 12/12, 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) |
+14
View File
@@ -478,6 +478,20 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure
- Full CTest: **8 / 8 passed** in 222.22 s.
- `clang-format --dry-run --Werror` passes on the changed C++ files.
## Track E3 Editor-Extension Watch Protocol (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: **12 / 12 passed** in 19.76 s, including
`watch_poll_reports_changed_paths`: a file created after daemon start is reported in
`watch_poll.changed` within bounded polling attempts, with `sequence`/`watch_events` counters.
- Full CTest: **8 / 8 passed** in 223.21 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).
+1 -1
View File
@@ -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 <pkg>` / `--changed-since <ref>`). | 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, and `vbs daemon ide generate` writes the editor presets over the socket. 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, and `vbs daemon ide poll` exposes a bounded editor-extension watch protocol (changed paths, sequence, overflow state). 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. |
---
+48 -9
View File
@@ -57,6 +57,7 @@ constexpr std::size_t kMaxDescribeProfileBytes = 128U;
constexpr std::size_t kMaxDescribeTargetNames = 128U;
constexpr std::size_t kMaxDescribeTargetNameBytes = 200U;
constexpr std::size_t kMaxBuildTargets = 64U;
constexpr std::size_t kMaxPendingChanges = 4096U;
Void::Result::Error make_error(Void::Result::ErrorKind kind, std::string message,
int system_errno = 0) {
@@ -769,6 +770,7 @@ struct DaemonServer::Impl {
[[nodiscard]] DaemonStatus current_status() const;
[[nodiscard]] std::string status_response() const;
DispatchResult dispatch(std::string_view line);
void record_watch_batch(const Watch::WatchBatch &batch);
void close_socket() noexcept {
if (listen_fd >= 0) {
@@ -798,6 +800,7 @@ struct DaemonServer::Impl {
std::uint64_t watch_events{0};
std::string last_event_path;
std::uint64_t sequence{0};
std::vector<std::filesystem::path> pending_changes;
};
DaemonStatus DaemonServer::Impl::current_status() const {
@@ -813,6 +816,28 @@ DaemonStatus DaemonServer::Impl::current_status() const {
return status;
}
void DaemonServer::Impl::record_watch_batch(const Watch::WatchBatch &batch) {
if (batch.overflowed || batch.rescan_required) {
static_cast<void>(watcher.rescan_watches());
++sequence;
}
if (batch.changed_paths.empty()) {
return;
}
watch_events += batch.changed_paths.size();
last_event_path = batch.changed_paths.back().string();
++sequence;
for (const auto &path : batch.changed_paths) {
pending_changes.push_back(path);
}
if (pending_changes.size() > kMaxPendingChanges) {
pending_changes.erase(
pending_changes.begin(),
pending_changes.begin() +
static_cast<std::ptrdiff_t>(pending_changes.size() - kMaxPendingChanges));
}
}
std::string DaemonServer::Impl::status_response() const {
const DaemonStatus status = current_status();
JsonValue::Object object;
@@ -854,6 +879,28 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
if (*name == "status") {
return {status_response(), false};
}
if (*name == "watch_poll") {
auto batch =
watcher.poll_events(std::chrono::milliseconds{0}, std::chrono::milliseconds{0});
if (!batch) {
return {error_response(std::format("watch_poll: {}", batch.error().format())), false};
}
record_watch_batch(*batch);
JsonValue::Array changed;
for (const auto &path : pending_changes) {
changed.emplace_back(path.string());
}
pending_changes.clear();
JsonValue::Object object;
object.emplace("ok", JsonValue{true});
object.emplace("op", JsonValue{std::string{"watch_poll"}});
object.emplace("sequence", JsonValue{static_cast<std::int64_t>(sequence)});
object.emplace("watch_events", JsonValue{static_cast<std::int64_t>(watch_events)});
object.emplace("changed", JsonValue{std::move(changed)});
object.emplace("overflowed", JsonValue{batch->overflowed});
object.emplace("rescan_required", JsonValue{batch->rescan_required});
return {serialize_response(JsonValue{std::move(object)}), false};
}
if (*name == "describe" || *name == "build" || *name == "ide_query" ||
*name == "ide_generate" || *name == "compdb_export") {
std::string profile_name{"debug"};
@@ -1195,15 +1242,7 @@ Void::Result::Result<void, Void::Result::Error> DaemonServer::run(std::stop_toke
// Watcher failures are surfaced through the next scan; the daemon stays alive.
continue;
}
if (batch->overflowed || batch->rescan_required) {
static_cast<void>(impl.watcher.rescan_watches());
++impl.sequence;
}
if (!batch->changed_paths.empty()) {
impl.watch_events += batch->changed_paths.size();
impl.last_event_path = batch->changed_paths.back().string();
++impl.sequence;
}
impl.record_watch_batch(*batch);
}
impl.close_socket();
return {};
+11 -2
View File
@@ -1445,6 +1445,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 == "watch_poll") {
request_json = R"({"op":"watch_poll"})";
} else if (sub == "ide_generate") {
if (opts.profile_arg.empty()) {
std::cerr << "vbs daemon ide generate: --profile must not be empty\n";
@@ -1492,8 +1494,9 @@ 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 == "describe" ? std::chrono::milliseconds{15000}
sub == "build" ? std::chrono::milliseconds{std::chrono::hours{1}}
: sub == "watch_poll" ? std::chrono::milliseconds{5000}
: sub == "describe" ? std::chrono::milliseconds{15000}
: (sub == "ide_query" || sub == "ide_generate" || sub == "compdb_export")
? std::chrono::milliseconds{30000}
: std::chrono::milliseconds{2000};
@@ -2453,6 +2456,9 @@ int main(int argc, char **argv) {
configure_daemon_common(daemon_ide_query_cmd);
daemon_ide_query_cmd.option_default("--profile", "-p", "Profile to query",
daemon_opts.profile_arg, "debug");
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);
auto &daemon_ide_generate_cmd =
daemon_ide_cmd.subcommand("generate", "Write editor configuration files");
configure_daemon_common(daemon_ide_generate_cmd);
@@ -2560,6 +2566,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] == "poll") {
daemon_sub = "watch_poll";
} else if (daemon_sub == "compdb" && parsed.matched_command_path.size() > 2 &&
parsed.matched_command_path[2] == "export") {
daemon_sub = "compdb_export";
+1
View File
@@ -52,6 +52,7 @@ check_process(0 "Usage: vbs daemon build .*--profile.*--target.*--jobs" "" daemo
check_process(0 "Usage: vbs daemon ide query .*--profile" "" daemon ide query --help)
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(2 "" "missing subcommand for 'vbs daemon'" daemon)
# Daemon-backed describe contract: start `vbs daemon run`, query the bounded graph summary over
+40
View File
@@ -596,6 +596,46 @@ void build(Void::Build::Project &project) {
Void::Testing::expect(std::filesystem::exists(options.project_root / ".clangd"));
}
VOID_TEST(Daemon, watch_poll_reports_changed_paths) {
auto temp = Void::FileSystem::TempDir::open("vbs_daemon_");
Void::Testing::require(temp.has_value());
const auto options = make_options(temp->path());
auto server = Void::Build::Daemon::DaemonServer::create(options);
Void::Testing::require(server.has_value());
const auto socket = server->socket_path();
Void::Result::Result<void, Void::Result::Error> run_result;
std::jthread worker{[&] { run_result = server->run(); }};
Void::Testing::require(wait_for_path(socket, std::chrono::seconds{5}));
{
std::ofstream probe{options.project_root / "probe.txt"};
probe << "changed\n";
Void::Testing::require(probe.good());
}
bool saw_probe = false;
for (int attempt = 0; attempt < 100 && !saw_probe; ++attempt) {
auto poll = request_object(socket, R"({"op":"watch_poll"})");
Void::Testing::require(poll.has_value());
for (const auto &path : string_array_field(*poll, "changed")) {
if (path.find("probe.txt") != std::string::npos) {
saw_probe = true;
}
}
if (!saw_probe) {
std::this_thread::sleep_for(std::chrono::milliseconds{20});
}
}
Void::Testing::expect(saw_probe);
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());