载入中...
搜索中...
未找到
AgentDevelopmentSession.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <set>
5#include <utility>
6
7namespace eve::dev {
8namespace {
9
10AgentDevelopmentResult applied() { return {"applied", {}}; }
11
12AgentDevelopmentResult rejected(std::string code, std::string message) {
13 return {std::move(code), std::move(message)};
14}
15
20 switch (from) {
28 default: return false;
29 }
30}
31
32} // namespace
33
38
40 std::string objective, std::vector<AgentAcceptanceCriterion> criteria) {
41 if (active()) return rejected("active-session", "A development session is already active");
42 if (objective.empty()) return rejected("invalid-objective", "objective must not be empty");
43 if (criteria.empty()) return rejected("invalid-criteria", "at least one acceptance criterion is required");
44 std::set<std::string> ids;
45 for (const auto& criterion : criteria) {
46 if (criterion.id.empty() || criterion.description.empty())
47 return rejected("invalid-criterion", "criterion id and description must not be empty");
48 if (!ids.insert(criterion.id).second)
49 return rejected("duplicate-criterion", "criterion ids must be unique");
50 }
51 reset();
52 sessionId_ = "agent.dev." + std::to_string(nextSession_++);
53 objective_ = std::move(objective);
54 criteria_ = std::move(criteria);
56 return applied();
57}
58
61 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
62 if (!active()) return rejected("session-terminal", "development session is already terminal");
63 if (!canAdvance(phase_, phase))
64 return rejected("invalid-transition", "requested phase does not follow the development workflow");
65 phase_ = phase;
66 return applied();
67}
68
70 AgentDevelopmentEvidence evidence) {
71 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
72 if (!active()) return rejected("session-terminal", "development session is already terminal");
73 if (evidence.kind.empty() || evidence.summary.empty())
74 return rejected("invalid-evidence", "evidence kind and summary must not be empty");
75 static const std::set<std::string> kEvidenceKinds{
76 "runtime-observation", "test", "screenshot", "checkpoint", "artifact", "manual", "play-trace"};
77 if (evidence.kind == "eval")
78 return rejected("invalid-evidence-kind", "required criteria reject eval evidence");
79 if (!kEvidenceKinds.contains(evidence.kind))
80 return rejected("invalid-evidence-kind", "evidence kind is not part of schema version one");
81 if (evidence.status != "pass" && evidence.status != "fail" && evidence.status != "pending")
82 return rejected("invalid-evidence-status", "evidence status must be pass, fail, or pending");
83 auto criterion = std::find_if(criteria_.begin(), criteria_.end(), [&](const auto& value) {
84 return value.id == evidence.criterionId;
85 });
86 if (criterion == criteria_.end())
87 return rejected("criterion-not-found", "evidence criterion was not declared by the session");
88 evidence.sequence = nextEvidence_++;
89 const bool visual = criterion->id == "visual" || criterion->id == "screenshot";
90 if (evidence.status == "pass" && evidence.kind != "manual") {
91 if (!visual || evidence.kind == "screenshot") criterion->passed = true;
92 }
93 if (evidence.status == "fail") criterion->passed = false;
94 evidence_.push_back(std::move(evidence));
95 return applied();
96}
97
99 std::string summary) {
100 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
101 if (!active()) return rejected("session-terminal", "development session is already terminal");
102 if (phase_ != AgentDevelopmentPhase::Verify)
103 return rejected("invalid-phase", "development session can complete only from verify");
104 if (!readyToComplete())
105 return rejected("acceptance-incomplete", "required acceptance criteria do not all have passing evidence");
106 if (summary.empty()) return rejected("invalid-summary", "completion summary must not be empty");
107 summary_ = std::move(summary);
109 return applied();
110}
111
113 std::string reason) {
114 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
115 if (!active()) return rejected("session-terminal", "development session is already terminal");
116 if (reason.empty()) return rejected("invalid-reason", "abort reason must not be empty");
117 summary_ = std::move(reason);
119 return applied();
120}
121
123 sessionId_.clear();
124 objective_.clear();
125 summary_.clear();
126 criteria_.clear();
127 evidence_.clear();
129 nextEvidence_ = 1;
130}
131
133 return !sessionId_.empty() && phase_ != AgentDevelopmentPhase::Complete &&
135}
136
138 return std::all_of(criteria_.begin(), criteria_.end(), [&](const auto& criterion) {
139 if (!criterion.required) return true;
140 if (!criterion.passed) return false;
141 const bool visual = criterion.id == "visual" || criterion.id == "screenshot";
142 if (!visual) return true;
143 return std::any_of(evidence_.begin(), evidence_.end(), [&](const auto& evidence) {
144 return evidence.criterionId == criterion.id && evidence.kind == "screenshot" &&
145 evidence.status == "pass";
146 });
147 });
148}
149
151 switch (phase) {
152 case AgentDevelopmentPhase::Discover: return "discover";
153 case AgentDevelopmentPhase::Modify: return "modify";
154 case AgentDevelopmentPhase::Run: return "run";
155 case AgentDevelopmentPhase::Observe: return "observe";
156 case AgentDevelopmentPhase::Verify: return "verify";
157 case AgentDevelopmentPhase::Recover: return "recover";
158 case AgentDevelopmentPhase::Complete: return "complete";
159 case AgentDevelopmentPhase::Aborted: return "aborted";
160 }
161 return "aborted";
162}
163
166 if (!phase) return rejected("invalid-output", "phase output must not be null");
167 if (name == "discover") *phase = AgentDevelopmentPhase::Discover;
168 else if (name == "modify") *phase = AgentDevelopmentPhase::Modify;
169 else if (name == "run") *phase = AgentDevelopmentPhase::Run;
170 else if (name == "observe") *phase = AgentDevelopmentPhase::Observe;
171 else if (name == "verify") *phase = AgentDevelopmentPhase::Verify;
172 else if (name == "recover") *phase = AgentDevelopmentPhase::Recover;
173 else return rejected("invalid-phase", "phase must be discover, modify, run, observe, verify, or recover");
174 return applied();
175}
176
177} // namespace eve::dev
double value
std::string from
float phase
Definition CaveMesh.cpp:58
std::string message
DiagnosticCode code
glm::uvec4 ids
HexCoordinates to
Cell the unit walks towards on this segment.
Definition HexUnits.cpp:64
std::string name
std::optional< InteractionSession > session
Definition Tactics.cpp:39
Process-owned state machine and evidence ledger for Agent game development.
AgentDevelopmentResult complete(std::string_view sessionId, std::string summary)
Complete only from Verify when every required criterion has passing evidence.
const std::string & summary() const
Terminal summary or abort reason.
const std::string & objective() const
User-supplied objective.
bool active() const
Whether a non-terminal session currently owns the workflow.
const std::vector< AgentAcceptanceCriterion > & criteria() const
Immutable acceptance snapshot owned by this session.
AgentDevelopmentPhase phase() const
Current workflow phase.
AgentDevelopmentResult abort(std::string_view sessionId, std::string reason)
Abort an active session with an explicit reason.
bool readyToComplete() const
Whether all required criteria have passing evidence.
const std::string & sessionId() const
Stable process-local session identity, invalidated by reset.
AgentDevelopmentResult start(std::string objective, std::vector< AgentAcceptanceCriterion > criteria)
Start one session; rejects empty objectives, duplicate criteria, or an active session.
AgentDevelopmentResult record(std::string_view sessionId, AgentDevelopmentEvidence evidence)
Append evidence; only pass evidence updates criterion satisfaction.
const std::vector< AgentDevelopmentEvidence > & evidence() const
Immutable evidence snapshot owned by this session.
AgentDevelopmentResult advance(std::string_view sessionId, AgentDevelopmentPhase phase)
Advance through the declared workflow graph without mutating game state.
void reset()
Clear all process-owned session metadata. Intended for host teardown and tests.
static AgentDevelopmentSession & instance()
Return the process-lifetime session authority.
AgentDevelopmentResult parseAgentDevelopmentPhase(std::string_view name, AgentDevelopmentPhase *phase)
Parse a stable JSON protocol phase name.
AgentDevelopmentPhase
Ordered stage of an Agent-driven game-development session.
std::string_view agentDevelopmentPhaseName(AgentDevelopmentPhase phase)
Stable JSON protocol name for a development phase.
Result< T > rejected(RuleId rule, std::string message, eve::DiagnosticCode code=eve::DiagnosticCode::PreconditionViolation)
Construct a Rejected result for invalid editing input or preconditions.
Result< T > applied(T value, std::vector< Diagnostic > diagnostics={})
Construct an Applied result with an owning payload and optional diagnostics.
Immutable evidence recorded against an acceptance condition.
Structured result for development-session state transitions.