feat: add gitea agentic runtime control plane
This commit is contained in:
65
engine/devops_agent/runtime.py
Normal file
65
engine/devops_agent/runtime.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from engine.devops_agent.evidence import write_run_artifact
|
||||
from engine.devops_agent.policies import RuntimePolicy
|
||||
|
||||
|
||||
def run_issue_comment_workflow(
|
||||
*,
|
||||
lock: dict[str, Any],
|
||||
provider: Any,
|
||||
event_payload: dict[str, Any],
|
||||
output_dir: str | Path,
|
||||
) -> dict[str, Any]:
|
||||
event = provider.parse_issue_comment_event(event_payload)
|
||||
repo = str(event["repo"])
|
||||
issue_number = int(event["issue_number"])
|
||||
issue = provider.get_issue(repo, issue_number)
|
||||
|
||||
policy = RuntimePolicy(
|
||||
safe_outputs=lock.get("safe_outputs") or {},
|
||||
path_scope=lock.get("policy", {}).get("path_scope") or [],
|
||||
)
|
||||
policy.assert_operation_allowed("add_comment")
|
||||
|
||||
verification_summary = (
|
||||
f"Workflow `{lock['workflow_name']}` processed issue #{issue_number} "
|
||||
f"and prepared evidence for review."
|
||||
)
|
||||
comment_response = provider.post_issue_comment(
|
||||
repo,
|
||||
issue_number,
|
||||
verification_summary,
|
||||
)
|
||||
|
||||
artifact: dict[str, Any] = {
|
||||
"run_id": f"{lock['workflow_name']}-issue-{issue_number}",
|
||||
"workflow_name": lock["workflow_name"],
|
||||
"provider": lock["provider"],
|
||||
"event": event,
|
||||
"plan_state": {
|
||||
"status": "pending_review",
|
||||
"repo": repo,
|
||||
"issue_number": issue_number,
|
||||
"issue_title": issue.get("title", ""),
|
||||
},
|
||||
"operations": [
|
||||
{
|
||||
"action": "add_comment",
|
||||
"issue_number": issue_number,
|
||||
"repo": repo,
|
||||
}
|
||||
],
|
||||
"evidence": {
|
||||
"issue_comment": comment_response,
|
||||
"verification_summary": verification_summary,
|
||||
},
|
||||
"result": "success",
|
||||
}
|
||||
artifact_path = write_run_artifact(output_dir, artifact)
|
||||
artifact["artifact_path"] = str(artifact_path.as_posix())
|
||||
artifact_path.write_text(__import__("json").dumps(artifact, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
return artifact
|
||||
Reference in New Issue
Block a user