载入中...
搜索中...
未找到
AgentDevelopmentSession.cpp
浏览该文件的文档.
2
4
5#include <algorithm>
6#include <set>
7#include <utility>
8
9namespace eve::dev {
10namespace {
11
12AgentDevelopmentResult applied() { return {"applied", {}}; }
13
14AgentDevelopmentResult rejected(std::string code, std::string message) { return {std::move(code), std::move(message)}; }
15
16bool escalateEdgeAllowed(std::string_view from, std::string_view to) {
17 if (from == to) return false;
18 if (from == "content.scene" && (to == "verify.play" || to == "content.map" || to == "workshop.rpg")) return true;
19 if (from == "content.map" && (to == "verify.play" || to == "content.scene" || to == "workshop.rpg")) return true;
20 if (from == "script.bind" && (to == "verify.play" || to == "fix.compile")) return true;
21 if (from == "verify.play" && (to == "content.scene" || to == "content.map" || to == "script.bind" ||
22 to == "workshop.rpg" || to == "fix.compile"))
23 return true;
24 if (from == "fix.compile" && (to == "script.bind" || to == "verify.play")) return true;
25 if (from == "workshop.rpg" &&
26 (to == "verify.play" || to == "content.scene" || to == "content.map" || to == "script.bind"))
27 return true;
28 return false;
29}
30
35 switch (from) {
43 default: return false;
44 }
45}
46
47} // namespace
48
53
55 std::vector<AgentAcceptanceCriterion> criteria,
56 std::string taskKind, std::string profile) {
57 if (active()) return rejected("active-session", "A development session is already active");
58 if (objective.empty()) return rejected("invalid-objective", "objective must not be empty");
59 if (criteria.empty()) return rejected("invalid-criteria", "at least one acceptance criterion is required");
60 std::string resolvedProfile;
61 std::string resolvedKind;
62 std::string errorCode;
63 std::string errorMessage;
64 if (!mcpResolveTaskProfile(taskKind, profile, &resolvedProfile, &resolvedKind, &errorCode, &errorMessage))
65 return rejected(std::move(errorCode), std::move(errorMessage));
66 std::set<std::string> ids;
67 for (const auto& criterion : criteria) {
68 if (criterion.id.empty() || criterion.description.empty())
69 return rejected("invalid-criterion", "criterion id and description must not be empty");
70 if (!ids.insert(criterion.id).second) return rejected("duplicate-criterion", "criterion ids must be unique");
71 }
72 reset();
73 sessionId_ = "agent.dev." + std::to_string(nextSession_++);
74 objective_ = std::move(objective);
75 taskKind_ = std::move(resolvedKind);
76 profile_ = std::move(resolvedProfile);
77 criteria_ = std::move(criteria);
79 escalateCount_ = 0;
80 mcpSetSessionProfile(profile_);
81 return applied();
82}
83
84AgentDevelopmentResult AgentDevelopmentSession::escalate(std::string_view sessionId, std::string_view toProfile) {
85 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
86 if (!active()) return rejected("session-terminal", "development session is already terminal");
87 std::string resolvedProfile;
88 std::string resolvedKind;
89 std::string errorCode;
90 std::string errorMessage;
91 if (!mcpResolveTaskProfile({}, toProfile, &resolvedProfile, &resolvedKind, &errorCode, &errorMessage))
92 return rejected(std::move(errorCode), std::move(errorMessage));
93 if (!escalateEdgeAllowed(profile_, resolvedProfile))
94 return rejected("invalid-escalate", "requested profile is not a legal escalate edge from the current profile");
95 profile_ = std::move(resolvedProfile);
96 taskKind_ = std::move(resolvedKind);
97 ++escalateCount_;
98 mcpSetSessionProfile(profile_);
99 return applied();
100}
101
103 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
104 if (!active()) return rejected("session-terminal", "development session is already terminal");
105 if (!canAdvance(phase_, phase))
106 return rejected("invalid-transition", "requested phase does not follow the development workflow");
107 phase_ = phase;
108 return applied();
109}
110
112 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
113 if (!active()) return rejected("session-terminal", "development session is already terminal");
114 if (evidence.kind.empty() || evidence.summary.empty())
115 return rejected("invalid-evidence", "evidence kind and summary must not be empty");
116 static const std::set<std::string> kEvidenceKinds{
117 "runtime-observation", "test", "screenshot", "checkpoint", "artifact", "manual", "play-trace"};
118 if (evidence.kind == "eval") return rejected("invalid-evidence-kind", "required criteria reject eval evidence");
119 if (!kEvidenceKinds.contains(evidence.kind))
120 return rejected("invalid-evidence-kind", "evidence kind is not part of schema version one");
121 if (evidence.status != "pass" && evidence.status != "fail" && evidence.status != "pending")
122 return rejected("invalid-evidence-status", "evidence status must be pass, fail, or pending");
123 auto criterion = std::find_if(criteria_.begin(), criteria_.end(),
124 [&](const auto& value) { return value.id == evidence.criterionId; });
125 if (criterion == criteria_.end())
126 return rejected("criterion-not-found", "evidence criterion was not declared by the session");
127 evidence.sequence = nextEvidence_++;
128 const bool visual = criterion->id == "visual" || criterion->id == "screenshot";
129 if (evidence.status == "pass" && evidence.kind != "manual") {
130 if (!visual || evidence.kind == "screenshot") criterion->passed = true;
131 }
132 if (evidence.status == "fail") criterion->passed = false;
133 evidence_.push_back(std::move(evidence));
134 return applied();
135}
136
137AgentDevelopmentResult AgentDevelopmentSession::complete(std::string_view sessionId, std::string summary) {
138 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
139 if (!active()) return rejected("session-terminal", "development session is already terminal");
140 if (phase_ != AgentDevelopmentPhase::Verify)
141 return rejected("invalid-phase", "development session can complete only from verify");
142 if (!readyToComplete())
143 return rejected("acceptance-incomplete", "required acceptance criteria do not all have passing evidence");
144 if (summary.empty()) return rejected("invalid-summary", "completion summary must not be empty");
145 summary_ = std::move(summary);
147 return applied();
148}
149
150AgentDevelopmentResult AgentDevelopmentSession::abort(std::string_view sessionId, std::string reason) {
151 if (sessionId != sessionId_) return rejected("session-not-found", "development session was not found");
152 if (!active()) return rejected("session-terminal", "development session is already terminal");
153 if (reason.empty()) return rejected("invalid-reason", "abort reason must not be empty");
154 summary_ = std::move(reason);
156 return applied();
157}
158
160 sessionId_.clear();
161 objective_.clear();
162 taskKind_.clear();
163 profile_.clear();
164 summary_.clear();
165 criteria_.clear();
166 evidence_.clear();
168 nextEvidence_ = 1;
169 escalateCount_ = 0;
171}
172
174 return !sessionId_.empty() && phase_ != AgentDevelopmentPhase::Complete && phase_ != AgentDevelopmentPhase::Aborted;
175}
176
178 return std::all_of(criteria_.begin(), criteria_.end(), [&](const auto& criterion) {
179 if (!criterion.required) return true;
180 if (!criterion.passed) return false;
181 const bool visual = criterion.id == "visual" || criterion.id == "screenshot";
182 if (!visual) return true;
183 return std::any_of(evidence_.begin(), evidence_.end(), [&](const auto& evidence) {
184 return evidence.criterionId == criterion.id && evidence.kind == "screenshot" && evidence.status == "pass";
185 });
186 });
187}
188
190 switch (phase) {
191 case AgentDevelopmentPhase::Discover: return "discover";
192 case AgentDevelopmentPhase::Modify: return "modify";
193 case AgentDevelopmentPhase::Run: return "run";
194 case AgentDevelopmentPhase::Observe: return "observe";
195 case AgentDevelopmentPhase::Verify: return "verify";
196 case AgentDevelopmentPhase::Recover: return "recover";
197 case AgentDevelopmentPhase::Complete: return "complete";
198 case AgentDevelopmentPhase::Aborted: return "aborted";
199 }
200 return "aborted";
201}
202
204 if (!phase) return rejected("invalid-output", "phase output must not be null");
205 if (name == "discover")
206 *phase = AgentDevelopmentPhase::Discover;
207 else if (name == "modify")
208 *phase = AgentDevelopmentPhase::Modify;
209 else if (name == "run")
210 *phase = AgentDevelopmentPhase::Run;
211 else if (name == "observe")
212 *phase = AgentDevelopmentPhase::Observe;
213 else if (name == "verify")
214 *phase = AgentDevelopmentPhase::Verify;
215 else if (name == "recover")
216 *phase = AgentDevelopmentPhase::Recover;
217 else
218 return rejected("invalid-phase", "phase must be discover, modify, run, observe, verify, or recover");
219 return applied();
220}
221
222} // namespace eve::dev
bool applied
std::string name
Definition ECS.cpp:154
std::string message
DiagnosticCode code
std::string to
std::string evidence
std::string from
Named Agent task profiles that narrow the MCP tool surface.
Object::Ptr value
float phase
std::optional< InteractionSession > session
Definition Tactics.cpp:39
Process-owned state machine and evidence ledger for Agent game development.
const std::string & taskKind() const
Resolved task kind for this session (verify when omitted at start).
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.
AgentDevelopmentResult escalate(std::string_view sessionId, std::string_view toProfile)
Narrow or widen the MCP tool surface along a declared escalate edge.
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.
AgentDevelopmentResult start(std::string objective, std::vector< AgentAcceptanceCriterion > criteria, std::string taskKind={}, std::string profile={})
Start one session; rejects empty objectives, duplicate criteria, or an active session.
bool readyToComplete() const
Whether all required criteria have passing evidence.
const std::string & profile() const
Resolved MCP task profile id (verify.play when omitted at start).
const std::string & sessionId() const
Stable process-local session identity, invalidated by reset.
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.
std::unordered_map< const void *, size_t > ids
Definition Snapshot.cpp:109
bool mcpResolveTaskProfile(std::string_view taskKind, std::string_view profile, std::string *outProfile, std::string *outTaskKind, std::string *errorCode, std::string *errorMessage)
Resolve taskKind + optional profile into a concrete profile id.
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.
void mcpSetSessionProfile(std::string_view profile)
Install or clear the session-level profile overlay.
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.
Immutable evidence recorded against an acceptance condition.
Structured result for development-session state transitions.