From f032c9f7fe7e4c649bf6ecbcfc4d2f8cfe7cd729 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sat, 5 Dec 2026 13:39:57 +0300 Subject: [PATCH] feat(ide): package the VS Code extension as a VSIX --- docs/agent-workflow/STATE.md | 2 + docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 12 +++ include/Void/Build/Editor/CompDb.hpp | 3 + include/Void/Build/Package/Archive.hpp | 6 ++ src/Editor/CompDb.cpp | 60 ++++++++++++++ src/Install/Installer.cpp | 76 +----------------- src/Main.cpp | 10 +++ src/Package/Archive.cpp | 106 +++++++++++++++++++++++++ tests/FullV1Tests.cpp | 67 ++++++++++++++++ 10 files changed, 269 insertions(+), 74 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index 36f1f43..bef0d0d 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -369,6 +369,8 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - **Wave 137 (UDIF/DMG-Style Packaging)**: `vbs install --archive FILE --archive-format dmg` writes a UDIF container - the deterministic tar payload followed by a 512-byte `koly` trailer with CRC-32 data/master checksums, segment ID, image variant and sector count. Validated independently: Python's `zlib.crc32` matches the stored checksum and the payload is a valid tar. A mountable macOS image still needs an HFS+/APFS payload writer (macOS-only). - **Wave 138 (Full CMake File API Reply Set)**: `vbs ide generate` now emits `cmakeFiles-v1` (configure inputs/outputs), `toolchains-v1` (C/CXX compiler identity) and `cache-v2` (build type, compilers, generator, profile) beside `codemodel-v2`, so CMake-aware IDEs (CLion, VS Code CMake Tools) get the complete reply set. +- **Wave 139 (Installable VSIX for the VS Code Plugin)**: `vbs ide plugin --editor vscode --vsix FILE` now packages the generated extension as a real `.vsix` (ZIP with `extension.vsixmanifest`, `[Content_Types].xml` and the sources under `extension/`), which `code --install-extension` accepts. The stored-ZIP writer moved from the installer into `Package::create_stored_zip` so both share it. The packaged extension's own test passes when extracted, and the C++ test parses the ZIP central directory and verifies every CRC. + ## Remaining future scope - **Superiority plan ([22-superiority-and-gaps.md](../roadmap/22-superiority-and-gaps.md), 2026-12-05)**: revised platform strategy - **macOS deferred**, **Windows via MinGW-w64 cross-compilation + Wine execution** (`dev cpp-gcc -p pkgsCross.mingwW64.stdenv.cc`, `dev cpp-gcc -p wine64`), native MSVC deferred; plus packaging parity (ZIP/DEB/RPM), IDE ecosystem, migration tooling, test-runner parity, benchmarks, CI runners, and remote execution in prioritized order. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index da4c9dd..ea0f39d 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -139,4 +139,5 @@ Base HEAD: `fe0d1a6` | Wave 136 (Parallel worker drain) | `--parallel N` lease/execute loops; exclusive registry leases prevent duplicates | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; E2E proves overlap and no duplicates, full CTest 8/8) | `src/Main.cpp`, `tests/RegistryTests.cpp`, docs | | Wave 137 (UDIF/DMG-style packaging) | `--archive-format dmg`: tar payload + koly trailer with CRC-32 | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; trailer parsed and CRC matches zlib, install test passes, full CTest 8/8) | `src/Install/Installer.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | | Wave 138 (Full CMake File API) | `cmakeFiles-v1`, `toolchains-v1`, `cache-v2` replies | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; IDE E2E passes, full CTest 8/8) | `src/Editor/CompDb.cpp`, `tests/FullV1Tests.cpp`, docs | +| Wave 139 (VSIX packaging) | `vbs ide plugin --vsix FILE`; shared `Package::create_stored_zip` | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Python zipfile validates the VSIX, packaged harness passes under Node, C++ test checks CRCs, full CTest 8/8) | `src/Editor/CompDb.cpp`, `src/Package/Archive.cpp`, `src/Main.cpp`, `tests/FullV1Tests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions) |"}] 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 6603eac..b001b85 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -1813,6 +1813,18 @@ VOID_INCLUDE_DIR=/tmp/opencode/vl-pin/include dev cpp -c bash fuzz/run.sh 30 (plus per-target and per-directory files), each parsed back and asserted in `ide_integration_compdb_build_cpp_and_editor_configs_end_to_end` (**passed**, 3.12 s). +## VSIX Packaging (GCC 16.2, pin `0002e74`) + +- `vbs ide plugin --editor vscode --output DIR --vsix dist/vbs-tools.vsix` writes the extension + sources plus a ZIP containing `extension.vsixmanifest`, `[Content_Types].xml` and + `extension/{package.json,extension.js,README.md,test/extension.test.js}`. +- Python `zipfile` reads it back: 6 entries, `testzip()` reports no CRC errors, the manifest has + `Id="vbs-tools"` and `Path="extension/package.json"`, and the packaged + `node test/extension.test.js` prints `extension tests passed: 6 commands`. +- `FullV1Tests.ide_plugin_assets_export_vscode_extension` parses the central directory itself, + recomputes each entry's CRC-32 and asserts the layout (**passed**, 34 ms). +- Full CTest: **8 / 8 passed** in 305.48 s. + ## 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/include/Void/Build/Editor/CompDb.hpp b/include/Void/Build/Editor/CompDb.hpp index 61cf19c..4bee6b0 100644 --- a/include/Void/Build/Editor/CompDb.hpp +++ b/include/Void/Build/Editor/CompDb.hpp @@ -125,6 +125,9 @@ struct IdePluginOptions { std::filesystem::path vbs_executable{"vbs"}; IdeKind editor{IdeKind::VsCode}; std::filesystem::path output_dir; + // Optional VSIX package path (VS Code only): a ZIP with extension.vsixmanifest, + // [Content_Types].xml and the extension sources under extension/. + std::optional vsix_path; bool force{false}; }; diff --git a/include/Void/Build/Package/Archive.hpp b/include/Void/Build/Package/Archive.hpp index 3894942..37f4822 100644 --- a/include/Void/Build/Package/Archive.hpp +++ b/include/Void/Build/Package/Archive.hpp @@ -36,6 +36,12 @@ create_deterministic_tar(const std::filesystem::path &output_tar, std::vector entries, std::int64_t reproducibility_epoch = 0); +// Creates a stored (uncompressed) deterministic ZIP archive, e.g. for Windows installers or +// editor-extension packages (VSIX). +[[nodiscard]] Void::Result::Result +create_stored_zip(const std::filesystem::path &output_zip, + const std::vector &entries); + // Packages a VBS project's source tree cleanly (retaining build.cpp, optional build.profiles.cpp, // build-support/**, and declared sources/headers while excluding .git, build/, .vbs/, secrets). [[nodiscard]] Void::Result::Result diff --git a/src/Editor/CompDb.cpp b/src/Editor/CompDb.cpp index ddcf809..c4aa2b8 100644 --- a/src/Editor/CompDb.cpp +++ b/src/Editor/CompDb.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -1451,6 +1452,65 @@ console.log('extension tests passed: ' + terminals.length + ' commands'); return std::unexpected{written.error()}; } } + + // Optional VSIX package: a ZIP that `code --install-extension` accepts. + if (options.vsix_path) { + const std::string vsix_manifest = + "\n" + "\n" + " \n" + " \n" + " VoidBuildSystem\n" + " Build, test, install and package with " + "VoidBuildSystem.\n" + " vbs\n" + " Other\n" + " Public\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + const std::string content_types = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n"; + const auto manifest_path = output / ".vsix" / "extension.vsixmanifest"; + const auto types_path = output / ".vsix" / "[Content_Types].xml"; + if (auto written = Platform::atomic_write_file(manifest_path, vsix_manifest, true); + !written) { + return std::unexpected{written.error()}; + } + if (auto written = Platform::atomic_write_file(types_path, content_types, true); !written) { + return std::unexpected{written.error()}; + } + std::vector vsix_entries{ + {"extension.vsixmanifest", manifest_path, 0644u}, + {"[Content_Types].xml", types_path, 0644u}}; + for (const auto &name : + {"package.json", "extension.js", "README.md", "test/extension.test.js"}) { + vsix_entries.push_back({std::string{"extension/"} + name, output / name, 0644u}); + } + if (options.vsix_path->has_parent_path()) { + std::filesystem::create_directories(options.vsix_path->parent_path(), ec); + } + if (auto zipped = Package::create_stored_zip(*options.vsix_path, vsix_entries); !zipped) { + return std::unexpected{zipped.error()}; + } + std::filesystem::remove_all(output / ".vsix", ec); + } return report; } diff --git a/src/Install/Installer.cpp b/src/Install/Installer.cpp index 2aebacb..486ced0 100644 --- a/src/Install/Installer.cpp +++ b/src/Install/Installer.cpp @@ -95,79 +95,6 @@ std::uint32_t crc32_bytes(std::string_view data) { return crc ^ 0xFFFFFFFFu; } -// Stored (uncompressed) deterministic ZIP archive of the installed files. -Void::Result::Result -write_stored_zip(const std::filesystem::path &output, - const std::vector &entries) { - struct Record { - std::string name; - std::uint32_t crc{0}; - std::uint32_t size{0}; - std::uint32_t offset{0}; - std::uint32_t mode{0644}; - }; - std::string local; - std::vector records; - for (const auto &entry : entries) { - auto content = Void::FileSystem::read_file(entry.source_file); - if (!content) { - return std::unexpected{content.error()}; - } - const auto crc = crc32_bytes(*content); - const auto size = static_cast(content->size()); - records.push_back( - {entry.archive_path, crc, size, static_cast(local.size()), entry.mode}); - put_u32(local, 0x04034b50u); - put_u16(local, 20); // version needed - put_u16(local, 0); // flags - put_u16(local, 0); // stored - put_u16(local, 0); // time - put_u16(local, 0x21); // 1980-01-01 - put_u32(local, crc); - put_u32(local, size); - put_u32(local, size); - put_u16(local, static_cast(entry.archive_path.size())); - put_u16(local, 0); // extra - local += entry.archive_path; - local += *content; - } - - std::string central; - for (const auto &record : records) { - put_u32(central, 0x02014b50u); - put_u16(central, 0x031e); // made by UNIX - put_u16(central, 20); - put_u16(central, 0); - put_u16(central, 0); - put_u16(central, 0); - put_u16(central, 0x21); - put_u32(central, record.crc); - put_u32(central, record.size); - put_u32(central, record.size); - put_u16(central, static_cast(record.name.size())); - put_u16(central, 0); // extra - put_u16(central, 0); // comment - put_u16(central, 0); // disk - put_u16(central, 0); // internal attrs - put_u32(central, (record.mode & 0777u) << 16); - put_u32(central, record.offset); - central += record.name; - } - - std::string eocd; - put_u32(eocd, 0x06054b50u); - put_u16(eocd, 0); - put_u16(eocd, 0); - put_u16(eocd, static_cast(records.size())); - put_u16(eocd, static_cast(records.size())); - put_u32(eocd, static_cast(central.size())); - put_u32(eocd, static_cast(local.size())); - put_u16(eocd, 0); - - std::string zip = local + central + eocd; - return Platform::atomic_write_file(output, zip, true); -} - std::string ar_member_header(std::string_view name, std::uint64_t size) { std::string header; std::string padded_name{name}; @@ -1132,7 +1059,8 @@ install_project(const Graph::ProjectDescription &description, const Graph::Build } if (options.archive_format == "zip") { - if (auto zipped = write_stored_zip(*options.archive_path, archive_entries); !zipped) { + if (auto zipped = Package::create_stored_zip(*options.archive_path, archive_entries); + !zipped) { return std::unexpected{zipped.error()}; } } else if (options.archive_format == "deb") { diff --git a/src/Main.cpp b/src/Main.cpp index aff584f..6d46479 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -3292,6 +3292,7 @@ struct IdeCmdOptions { std::optional compiler_arg; std::string editor_name{"all"}; std::optional plugin_output_arg; + std::optional plugin_vsix_arg; bool force{false}; }; @@ -3320,6 +3321,13 @@ int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) { plugin_opts.editor = ide_kind; plugin_opts.output_dir = *opts.plugin_output_arg; plugin_opts.force = opts.force; + if (opts.plugin_vsix_arg) { + if (ide_kind != Editor::IdeKind::VsCode) { + std::cerr << "vbs ide plugin: --vsix is only supported for vscode\n"; + return 2; + } + plugin_opts.vsix_path = *opts.plugin_vsix_arg; + } if (auto exe = Platform::current_executable_path(); exe) { plugin_opts.vbs_executable = *exe; } @@ -4006,6 +4014,8 @@ int main(int argc, char **argv) { ide_plugin_cmd .option_default("--editor", "-e", "Editor preset (vscode)", ide_opts.editor_name, "vscode") .option("--output", "-o", "Output directory", ide_opts.plugin_output_arg) + .option("--vsix", "", "Package the VS Code extension as a .vsix (ZIP)", + ide_opts.plugin_vsix_arg) .flag("--force", "", "Overwrite existing plugin files", ide_opts.force); auto &ide_gen_cmd = ide_cmd.subcommand("generate", "Generate .clangd, .vscode/, .zed/, and .idea/ IDE configs"); diff --git a/src/Package/Archive.cpp b/src/Package/Archive.cpp index 41f1cae..b2af522 100644 --- a/src/Package/Archive.cpp +++ b/src/Package/Archive.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -118,6 +119,111 @@ create_source_package(const std::filesystem::path &project_root, return create_deterministic_tar(output_tar, std::move(entries), reproducibility_epoch); } +namespace { + +void zip_put_u16(std::string &out, std::uint16_t value) { + out.push_back(static_cast(value & 0xFFu)); + out.push_back(static_cast((value >> 8) & 0xFFu)); +} + +void zip_put_u32(std::string &out, std::uint32_t value) { + for (int shift = 0; shift < 32; shift += 8) { + out.push_back(static_cast((value >> shift) & 0xFFu)); + } +} + +std::uint32_t zip_crc32(std::string_view data) { + static const auto table = [] { + std::array t{}; + for (std::uint32_t i = 0; i < 256; ++i) { + std::uint32_t c = i; + for (int k = 0; k < 8; ++k) { + c = (c & 1u) != 0u ? (0xEDB88320u ^ (c >> 1)) : (c >> 1); + } + t[i] = c; + } + return t; + }(); + std::uint32_t crc = 0xFFFFFFFFu; + for (const char ch : data) { + crc = table[(crc ^ static_cast(ch)) & 0xFFu] ^ (crc >> 8); + } + return crc ^ 0xFFFFFFFFu; +} + +} // namespace + +Void::Result::Result +create_stored_zip(const std::filesystem::path &output_zip, + const std::vector &entries) { + struct Record { + std::string name; + std::uint32_t crc{0}; + std::uint32_t size{0}; + std::uint32_t offset{0}; + std::uint32_t mode{0644}; + }; + std::string local; + std::vector records; + for (const auto &entry : entries) { + auto content = Void::FileSystem::read_file(entry.source_file); + if (!content) { + return std::unexpected{content.error()}; + } + const auto crc = zip_crc32(*content); + const auto size = static_cast(content->size()); + records.push_back( + {entry.archive_path, crc, size, static_cast(local.size()), entry.mode}); + zip_put_u32(local, 0x04034b50u); + zip_put_u16(local, 20); // version needed + zip_put_u16(local, 0); // flags + zip_put_u16(local, 0); // stored + zip_put_u16(local, 0); // time + zip_put_u16(local, 0x21); // 1980-01-01 + zip_put_u32(local, crc); + zip_put_u32(local, size); + zip_put_u32(local, size); + zip_put_u16(local, static_cast(entry.archive_path.size())); + zip_put_u16(local, 0); // extra + local += entry.archive_path; + local += *content; + } + + std::string central; + for (const auto &record : records) { + zip_put_u32(central, 0x02014b50u); + zip_put_u16(central, 0x031e); // made by UNIX + zip_put_u16(central, 20); + zip_put_u16(central, 0); + zip_put_u16(central, 0); + zip_put_u16(central, 0); + zip_put_u16(central, 0x21); + zip_put_u32(central, record.crc); + zip_put_u32(central, record.size); + zip_put_u32(central, record.size); + zip_put_u16(central, static_cast(record.name.size())); + zip_put_u16(central, 0); // extra + zip_put_u16(central, 0); // comment + zip_put_u16(central, 0); // disk + zip_put_u16(central, 0); // internal attrs + zip_put_u32(central, (record.mode & 0777u) << 16); + zip_put_u32(central, record.offset); + central += record.name; + } + + std::string eocd; + zip_put_u32(eocd, 0x06054b50u); + zip_put_u16(eocd, 0); + zip_put_u16(eocd, 0); + zip_put_u16(eocd, static_cast(records.size())); + zip_put_u16(eocd, static_cast(records.size())); + zip_put_u32(eocd, static_cast(central.size())); + zip_put_u32(eocd, static_cast(local.size())); + zip_put_u16(eocd, 0); + + return Platform::atomic_write_file(output_zip, local + central + eocd, true); +} + Void::Result::Result extract_safe_tar(const std::filesystem::path &tar_path, const std::filesystem::path &destination_dir, const ArchiveLimits &limits) { diff --git a/tests/FullV1Tests.cpp b/tests/FullV1Tests.cpp index b23d180..06f923f 100644 --- a/tests/FullV1Tests.cpp +++ b/tests/FullV1Tests.cpp @@ -1218,6 +1218,73 @@ VOID_TEST(FullV1Tests, ide_plugin_assets_export_vscode_extension) { Void::Testing::expect(manifest_text->find("\"test\": \"node test/extension.test.js\"") != std::string::npos); + // VSIX packaging: a ZIP with the VS Code extension layout and valid CRCs. + { + auto vsix_options = options; + vsix_options.output_dir = tmp / "vbs-tools-vsix"; + vsix_options.vsix_path = tmp / "dist" / "vbs-tools.vsix"; + auto vsix_report = Editor::generate_ide_plugin_assets(vsix_options); + Void::Testing::require(vsix_report.has_value()); + auto vsix_bytes = Void::FileSystem::read_file(*vsix_options.vsix_path); + Void::Testing::require(vsix_bytes.has_value()); + const std::string_view zip = *vsix_bytes; + const auto read_u16 = [&](std::size_t o) { + return static_cast(static_cast(zip[o]) | + (static_cast(zip[o + 1]) << 8)); + }; + const auto read_u32 = [&](std::size_t o) { + std::uint32_t v = 0; + for (int i = 3; i >= 0; --i) { + v = (v << 8) | static_cast(zip[o + static_cast(i)]); + } + return v; + }; + const auto eocd = zip.rfind(std::string_view{"PK\x05\x06", 4}); + Void::Testing::require(eocd != std::string_view::npos); + const auto entry_count = read_u16(eocd + 10); + std::size_t offset = read_u32(eocd + 16); + std::vector names; + std::size_t checked = 0; + for (std::uint16_t i = 0; i < entry_count; ++i) { + Void::Testing::require(zip.substr(offset, 4) == std::string_view{"PK\x01\x02", 4}); + const auto crc_expected = read_u32(offset + 16); + const auto name_len = read_u16(offset + 28); + const auto extra_len = read_u16(offset + 30); + const auto comment_len = read_u16(offset + 32); + const auto local_offset = read_u32(offset + 42); + names.emplace_back(zip.substr(offset + 46, name_len)); + // Recompute the CRC from the local entry data. + const auto local_name_len = read_u16(local_offset + 26); + const auto local_extra_len = read_u16(local_offset + 28); + const auto data_size = read_u32(local_offset + 22); + const auto data_start = + static_cast(local_offset) + 30 + local_name_len + local_extra_len; + std::uint32_t crc = 0xFFFFFFFFu; + for (std::size_t b = data_start; b < data_start + data_size; ++b) { + crc ^= static_cast(zip[b]); + for (int bit = 0; bit < 8; ++bit) { + crc = (crc >> 1) ^ (0xEDB88320u & (0u - (crc & 1u))); + } + } + Void::Testing::expect_eq(~crc, crc_expected); + ++checked; + offset += 46 + name_len + extra_len + comment_len; + } + Void::Testing::expect_eq(checked, std::size_t{6}); + const auto has_entry = [&](std::string_view name) { + return std::ranges::contains(names, name); + }; + Void::Testing::expect(has_entry("extension.vsixmanifest")); + Void::Testing::expect(has_entry("[Content_Types].xml")); + Void::Testing::expect(has_entry("extension/package.json")); + Void::Testing::expect(has_entry("extension/extension.js")); + Void::Testing::expect(has_entry("extension/test/extension.test.js")); + Void::Testing::expect(zip.find("Id=\"vbs-tools\"") != std::string_view::npos); + Void::Testing::expect(zip.find("Path=\"extension/package.json\"") != + std::string_view::npos); + Void::Testing::expect(!std::filesystem::exists(vsix_options.output_dir / ".vsix")); + } + auto zed_options = options; zed_options.editor = Editor::IdeKind::Zed; zed_options.output_dir = tmp / "vbs-zed";