#pragma once #include #include #include #include #include #include #include #include #include #include namespace vls::gcc { namespace Protocol = Void::LanguageServer::Protocol; using TraceResult = std::expected; // The journal is exclusively created and binds the immutable input to this invocation. // Commands are journalled before dispatch. Acknowledgement is a separate compiler event. class Trace { public: static std::expected, std::string> create(const std::filesystem::path &output, std::string_view source, std::string_view compiler_sha, std::string_view nonce, std::int64_t pid); ~Trace(); [[nodiscard]] TraceResult event(std::string_view line); [[nodiscard]] TraceResult authorize(std::uint32_t stop, std::string_view action); [[nodiscard]] std::optional stopped() const; [[nodiscard]] bool ended() const; [[nodiscard]] std::string_view terminal() const; [[nodiscard]] Protocol::Json inspection() const; [[nodiscard]] TraceResult finish(std::string_view outcome, int exit_code, std::string_view diagnostics); private: struct State; explicit Trace(std::unique_ptr); std::unique_ptr state_; }; struct ReplayEvent { std::uint32_t sequence; std::string_view kind; std::optional frame; std::optional parent; // Present together on a compiler resumed event. std::optional acknowledged_stop; std::optional acknowledged_action; }; struct ReplayValuePoint { std::uint32_t value_sequence; std::optional stop_sequence; }; struct ReplayMetadata { std::string_view backend; std::string_view nonce; std::int64_t pid; std::string_view compiler_sha256; std::string_view source_sha256; bool partial; bool corrupt; std::optional journal_error; std::optional outcome; std::optional exit_code; }; // Views borrow this recording. A shared owner keeps its validated prefix and raw bytes alive. class ReplayRecording { public: static std::expected, std::string> open(const std::filesystem::path &absolute_path); ~ReplayRecording(); [[nodiscard]] ReplayMetadata metadata() const; [[nodiscard]] std::string_view source_bytes() const; [[nodiscard]] std::optional diagnostic_bytes() const; [[nodiscard]] std::size_t event_count() const; // Zero-based offset; offset == event_count() is an empty page. Larger offsets or // requests above max_page_size return an error. The span is an O(1) immutable slice. static constexpr std::size_t max_page_size = 256; [[nodiscard]] std::expected, std::string> event_page(std::size_t offset, std::size_t count) const; // Strictly beyond the entire value/optional-stop pair. Omit the anchor for first/last. // A boundary returns an empty optional; a sequence outside the verified prefix is an error. [[nodiscard]] std::expected, std::string> next_value(std::optional after = {}) const; [[nodiscard]] std::expected, std::string> previous_value(std::optional before = {}) const; // Owned JSON uses Trace's frame schema. Historical state is immediately after the event. // final_cursor also sees subsequent command authorization and final stop consumption. // Each query copies only its active frames, last leave and identity, at most 4096 events deep. [[nodiscard]] std::expected cursor_at(std::uint32_t sequence) const; [[nodiscard]] Protocol::Json final_cursor() const; private: struct State; explicit ReplayRecording(std::unique_ptr); std::unique_ptr state_; }; [[nodiscard]] std::expected replay(const std::filesystem::path &journal, std::optional sequence); } // namespace vls::gcc