Vape / agents /build_request.py
DetVape's picture
Sync from GitHub via hub-sync
6c61757 verified
Raw History Blame Contribute Delete
6.39 kB
"""
VAPE build-request agent β€” turns a labeled GitHub issue into a real,
reviewable PR. This is the concrete instantiation of "VAPE can build
tools/apps/anything needed": open an issue describing what you want built,
apply the `vape-build` label, and Builder (agents/builder.py's
generate_project()) attempts a real multi-file implementation grounded in
Memory and scoped to VAPE's actual specialization areas and tech stack.
Safety boundary, same principle as self_improve.py: generated files land in
an isolated build-requests/issue-<N>-<slug>/ directory via a PR, never
directly into existing production files β€” a human decides whether/how/where
to actually integrate it. Builder's own security validation (blocks
eval/exec/shell/unsafe deserialization) is the first gate; PR review is the
second. Labeling an issue is itself a maintainer action by default on
GitHub (not available to arbitrary external commenters), which is the gate
on who can trigger a build at all.
Triggered by .github/workflows/build-request.yml on the `issues: labeled`
event (real-time, not polled) β€” reads the issue number/title/body from
environment variables the workflow passes from the GitHub event payload
directly, since the workflow already has that data for free.
"""
import os
import re
import sys
from datetime import datetime, timezone
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from agents.builder import Builder, validate_security # noqa: E402
from agents._build_pr import open_build_pr as _open_build_pr # noqa: E402
try:
from skillforge.memory.retriever import append_to_memory # noqa: E402
except Exception:
append_to_memory = None
_REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
REPORTS_DIR = os.path.join(_REPO_ROOT, "reports")
def _now_stamp():
return datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
def open_build_pr(issue_number, issue_title, files, warnings):
slug = re.sub(r"[^a-z0-9]+", "-", issue_title.lower()).strip("-")[:40]
branch = f"vape-build-{issue_number}-{slug}-{_now_stamp()}"
out_dir_rel = os.path.join("build-requests", f"issue-{issue_number}-{slug}")
readme = (
f"# VAPE build request β€” issue #{issue_number}\n\n"
f"**Requested:** {issue_title}\n\n"
f"**Security review:** {'clean' if not warnings else '; '.join(warnings)}\n\n"
"This is a PROPOSAL, not applied automatically. A human reviews this PR and "
"decides whether/how/where to integrate it into the real codebase.\n\n"
"## Files\n" + "\n".join(f"- `{p}`" for p in files)
)
body = (
f"Addresses #{issue_number}\n\n"
f"**Security review:** {'clean' if not warnings else ', '.join(warnings)}\n\n"
f"Generated by `agents/build_request.py` from the issue above. Files land under "
f"`{out_dir_rel}/` for review β€” nothing was applied to the existing codebase "
f"automatically.\n\n## Files\n" + "\n".join(f"- `{p}`" for p in files)
)
return _open_build_pr(branch, out_dir_rel, f"VAPE build: {issue_title}", body, readme, files)
def _log_lesson(issue_number, issue_title, files, pr_url):
if append_to_memory is None:
return
outcome = "opened a real PR" if pr_url else ("generated files but PR creation failed/skipped" if files else "generated nothing this cycle")
try:
append_to_memory(
category="lesson",
title=f"build_request: issue #{issue_number} β€” {issue_title[:80]} β€” {outcome}",
content=f"Files: {list(files.keys())}\nOutcome: {outcome}" + (f"\nPR: {pr_url}" if pr_url else ""),
source="agents/build_request.py",
tags=["build-request", "builder"],
confidence=0.75,
metadata={"issue_number": issue_number, "pr_url": pr_url, "files": list(files.keys())},
)
except Exception as e:
print(f"[BuildRequest] could not log lesson: {e}")
def main():
issue_number = os.environ.get("ISSUE_NUMBER", "").strip()
issue_title = os.environ.get("ISSUE_TITLE", "").strip()
issue_body = os.environ.get("ISSUE_BODY", "").strip()
os.makedirs(REPORTS_DIR, exist_ok=True)
report_path = os.path.join(REPORTS_DIR, f"build_request_{_now_stamp()}.md")
if not issue_number or not issue_title:
with open(report_path, "w") as f:
f.write("# VAPE Build Request β€” missing issue data\n\n"
"ISSUE_NUMBER/ISSUE_TITLE environment variables were not set β€” aborting "
"rather than fabricating a target.\n")
print("[BuildRequest] missing issue number/title β€” aborting.")
return
builder = Builder()
if not builder.llm_ready:
with open(report_path, "w") as f:
f.write(f"# VAPE Build Request β€” issue #{issue_number}\n\n"
"No LLM provider available this cycle β€” logging the request for a "
"future run instead of fabricating a build.\n")
print("[BuildRequest] no LLM available β€” skipping.")
return
task = (
f"GitHub issue #{issue_number}: {issue_title}\n\n{issue_body}\n\n"
"This request came from a real GitHub issue on VAPE's own repository, labeled "
"'vape-build' by a maintainer. Build exactly what's asked, scoped to VAPE's real "
"stack and specialization areas β€” never invent scope beyond the issue text."
)
files, metadata = builder.generate_project(task=task, review=True, tier="deep")
combined = "\n\n".join(files.values()) if files else ""
_, warnings = validate_security(combined, task) if files else (True, [])
pr_url = open_build_pr(issue_number, issue_title, files, warnings) if files else None
_log_lesson(issue_number, issue_title, files, pr_url)
report = (
f"# VAPE Build Request β€” issue #{issue_number}: {issue_title}\n\n"
"## Files generated\n"
+ ("\n".join(f"- `{p}`" for p in files) if files else "None β€” Builder produced no usable FILE blocks this cycle.")
+ "\n\n"
+ (f"PR opened: {pr_url}\n" if pr_url else "No PR opened (see log for why).\n")
)
with open(report_path, "w") as f:
f.write(report)
print(f"[BuildRequest] cycle complete. Report: {os.path.relpath(report_path, _REPO_ROOT)}")
if __name__ == "__main__":
main()