// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include #include #include #include #include namespace zen { struct HistoryRecord { std::string Id; std::string Ts; std::string Exe; std::string Mode; std::string Cwd; std::string Path; std::string CmdLine; uint32_t Pid = 0; }; /// Append an invocation record to the per-user history file. /// /// Must be called BEFORE CommandLineConverter has had a chance to mutate argv /// (which strips quoting and re-parses the Windows command line). Typical call /// site is right after InstallCrashHandler() in main(). /// /// Never throws. Any I/O or parsing failure is swallowed so that logging cannot /// break the actual command being run. If argv contains the single-token /// `--enable-execution-history=false` (or `=0` / `=no`), returns without doing /// anything. /// /// Exe should be "zen" or "zenserver". Mode is zenserver-only (hub/store/ /// compute/proxy/test); pass an empty string_view for zen. /// /// ExcludeSubcommands is an optional list of subcommand names. If argv[1] /// matches any entry, logging is skipped. Used e.g. so `zen history` does not /// pollute the history file it inspects. void LogInvocation(std::string_view Exe, std::string_view Mode, int argc, char** argv, std::initializer_list ExcludeSubcommands = {}) noexcept; /// Read the most recent MaxRecords entries from the history file (newest last). /// Returns an empty vector if the file does not exist or is unreadable. std::vector ReadInvocationHistory(size_t MaxRecords = 100); /// Resolve the per-user history file path. Does not create the file or the /// parent directory. Never throws; returns an empty path on any error. std::filesystem::path GetInvocationHistoryPath() noexcept; void invocationhistory_forcelink(); // internal } // namespace zen