Step 158: add agent workflow recorder

This commit is contained in:
Bill
2026-02-09 19:36:45 -07:00
parent 9624e8e16f
commit c21c52f55b
6 changed files with 236 additions and 1 deletions

View File

@@ -42,6 +42,7 @@
#include "ZoomUtils.h"
#include "TerminalPanel.h"
#include "WebSocketServer.h"
#include "WorkflowRecorder.h"
#include "BuildSystem.h"
#include "DependencyPanel.h"
#include "LibraryIndexer.h"
@@ -176,6 +177,7 @@ struct EditorState {
int agentPort = 8765;
std::vector<std::string> agentLog;
std::map<std::string, AgentRole> agentRoles;
WorkflowRecorder workflowRecorder;
BuildSystem::Type buildType = BuildSystem::Type::None;
std::vector<BuildError> buildErrors;
std::string lastBuildOutput;
@@ -922,6 +924,7 @@ struct EditorState {
std::string method = req.value("method", "");
bool ok = !res.contains("error");
logAgentEvent("RPC " + sid + " " + method + (ok ? " ok" : " error"));
workflowRecorder.record(sid, req, res);
});
if (agentServer->start(agentPort)) {
logAgentEvent("Agent server started on port " + std::to_string(agentPort));
@@ -1200,6 +1203,52 @@ struct EditorState {
return response;
}
if (method == "startWorkflowRecording") {
auto params = request.contains("params") ? request["params"] : json::object();
std::string name = params.value("name", "workflow");
workflowRecorder.startRecording(name, sessionId);
response["result"] = {
{"recording", true},
{"name", name}
};
return response;
}
if (method == "stopWorkflowRecording") {
response["result"] = workflowRecorder.stopRecording();
return response;
}
if (method == "getWorkflowRecording") {
response["result"] = workflowRecorder.exportWorkflow();
return response;
}
if (method == "replayWorkflow") {
auto params = request.contains("params") ? request["params"] : json::object();
if (!params.contains("workflow")) {
response["error"] = {{"code", -32602}, {"message", "Missing workflow payload"}};
return response;
}
WorkflowRecorder temp;
if (!temp.loadWorkflow(params["workflow"])) {
response["error"] = {{"code", -32602}, {"message", "Invalid workflow payload"}};
return response;
}
auto requests = temp.buildReplayRequests();
json results = json::array();
workflowRecorder.setReplaying(true);
for (auto& req : requests) {
results.push_back(processAgentRequest(req, sessionId));
}
workflowRecorder.setReplaying(false);
response["result"] = {
{"count", results.size()},
{"responses", results}
};
return response;
}
if (method == "getAnnotationSuggestions") {
if (!AgentPermissionPolicy::canInvoke(role, method)) {
response["error"] = {{"code", -32031}, {"message", "Role not permitted"}};