yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
proposal_registry.h
Go to the documentation of this file.
1#ifndef YAZE_SRC_CLI_SERVICE_PROPOSAL_REGISTRY_H_
2#define YAZE_SRC_CLI_SERVICE_PROPOSAL_REGISTRY_H_
3
4#include <filesystem>
5#include <memory>
6#include <mutex>
7#include <optional>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
12#include "absl/status/status.h"
13#include "absl/status/statusor.h"
14#include "absl/strings/string_view.h"
15#include "absl/time/time.h"
16
17namespace yaze {
18namespace cli {
19
20// ProposalRegistry tracks agent-generated ROM modification proposals,
21// storing metadata, diffs, execution logs, and optional screenshots for
22// human review. Each proposal is associated with a sandbox ROM copy.
23//
24// Proposals follow a lifecycle:
25// 1. Created - agent generates a proposal during `agent run`
26// 2. Reviewed - user inspects via `agent diff` or TUI
27// 3. Accepted - changes committed to main ROM via `agent commit`
28// 4. Rejected - sandbox cleaned up via `agent revert`
30 public:
31 enum class ProposalStatus {
32 kPending, // Created but not yet reviewed
33 kAccepted, // User accepted the changes
34 kRejected, // User rejected the changes
35 };
36
38 std::string id;
39 std::string sandbox_id;
40 std::filesystem::path sandbox_directory;
41 std::filesystem::path sandbox_rom_path;
42 std::string description;
43 std::string prompt; // Original agent prompt that created this proposal
45 absl::Time created_at;
46 std::optional<absl::Time> reviewed_at;
47
48 // File paths relative to proposal directory
49 std::filesystem::path diff_path;
50 std::filesystem::path log_path;
51 std::vector<std::filesystem::path> screenshots;
52
53 // Statistics
56 };
57
58 static ProposalRegistry& Instance();
59
60 // Set the root directory for storing proposal data. If not set, uses
61 // YAZE_PROPOSAL_ROOT env var or defaults to system temp directory.
62 void SetRootDirectory(const std::filesystem::path& root);
63
64 const std::filesystem::path& RootDirectory() const;
65
66 // Creates a new proposal linked to the given sandbox. The proposal directory
67 // is created under the root, and metadata is initialized.
68 absl::StatusOr<ProposalMetadata> CreateProposal(
69 absl::string_view sandbox_id,
70 const std::filesystem::path& sandbox_rom_path, absl::string_view prompt,
71 absl::string_view description);
72
73 // Records a diff between original and modified ROM for the proposal.
74 // The diff content is written to a file within the proposal directory.
75 absl::Status RecordDiff(const std::string& proposal_id,
76 absl::string_view diff_content);
77
78 // Appends log output from command execution to the proposal's log file.
79 absl::Status AppendLog(const std::string& proposal_id,
80 absl::string_view log_entry);
81
82 // Adds a screenshot path to the proposal metadata. Screenshots should
83 // be copied into the proposal directory before calling this.
84 absl::Status AddScreenshot(const std::string& proposal_id,
85 const std::filesystem::path& screenshot_path);
86
87 // Updates the number of commands executed for a proposal. Used to track
88 // how many CLI commands ran when generating the proposal.
89 absl::Status UpdateCommandStats(const std::string& proposal_id,
90 int commands_executed);
91
92 // Updates the proposal status (pending -> accepted/rejected) and sets
93 // the review timestamp.
94 absl::Status UpdateStatus(const std::string& proposal_id,
95 ProposalStatus status);
96
97 // Returns the metadata for a specific proposal.
98 absl::StatusOr<ProposalMetadata> GetProposal(
99 const std::string& proposal_id) const;
100
101 // Lists all proposals, optionally filtered by status.
102 std::vector<ProposalMetadata> ListProposals(
103 std::optional<ProposalStatus> filter_status = std::nullopt) const;
104
105 // Returns the most recently created proposal that is still pending.
106 absl::StatusOr<ProposalMetadata> GetLatestPendingProposal() const;
107
108 // Removes a proposal and its associated files from disk and memory.
109 absl::Status RemoveProposal(const std::string& proposal_id);
110
111 // Deletes all proposals older than the specified age.
112 absl::StatusOr<int> CleanupOlderThan(absl::Duration max_age);
113
114 private:
116
117 absl::Status EnsureRootExistsLocked();
118 absl::Status LoadProposalsFromDiskLocked();
119 std::string GenerateProposalIdLocked();
120 std::filesystem::path ProposalDirectory(absl::string_view proposal_id) const;
121 absl::Status WriteMetadataLocked(const ProposalMetadata& metadata) const;
122
123 std::filesystem::path root_directory_;
124 mutable std::mutex mutex_;
125 std::unordered_map<std::string, ProposalMetadata> proposals_;
126 int sequence_ = 0;
127};
128
129} // namespace cli
130} // namespace yaze
131
132#endif // YAZE_SRC_CLI_SERVICE_PROPOSAL_REGISTRY_H_
static ProposalRegistry & Instance()
absl::Status AppendLog(const std::string &proposal_id, absl::string_view log_entry)
absl::StatusOr< ProposalMetadata > GetLatestPendingProposal() const
std::filesystem::path root_directory_
absl::Status UpdateStatus(const std::string &proposal_id, ProposalStatus status)
absl::Status WriteMetadataLocked(const ProposalMetadata &metadata) const
std::unordered_map< std::string, ProposalMetadata > proposals_
absl::Status AddScreenshot(const std::string &proposal_id, const std::filesystem::path &screenshot_path)
std::filesystem::path ProposalDirectory(absl::string_view proposal_id) const
absl::Status RemoveProposal(const std::string &proposal_id)
absl::Status RecordDiff(const std::string &proposal_id, absl::string_view diff_content)
void SetRootDirectory(const std::filesystem::path &root)
const std::filesystem::path & RootDirectory() const
std::vector< ProposalMetadata > ListProposals(std::optional< ProposalStatus > filter_status=std::nullopt) const
absl::StatusOr< ProposalMetadata > CreateProposal(absl::string_view sandbox_id, const std::filesystem::path &sandbox_rom_path, absl::string_view prompt, absl::string_view description)
absl::StatusOr< ProposalMetadata > GetProposal(const std::string &proposal_id) const
absl::StatusOr< int > CleanupOlderThan(absl::Duration max_age)
absl::Status UpdateCommandStats(const std::string &proposal_id, int commands_executed)
std::vector< std::filesystem::path > screenshots