neural-sync/scripts/integrate_pixelle.py

101 lines
3.9 KiB
Python

import asyncio
import httpx
import os
import subprocess
import json
API_BASE = "http://127.0.0.1:8000"
PIXELLE_PATH = os.path.abspath("Pixelle-Video")
async def main():
print(f"Integrating Pixelle-Video from {PIXELLE_PATH}...")
# 1. Read README for Context
readme_path = os.path.join(PIXELLE_PATH, "README.md")
if not os.path.exists(readme_path):
print("README.md not found, using default description.")
description = "Pixelle-Video: AI Automated Short Video Engine."
else:
with open(readme_path, "r") as f:
description = f.read()[:2000] # Limit length
# 2. Create Context Node
async with httpx.AsyncClient(trust_env=False) as client:
print("Creating Context Node...")
try:
resp = await client.post(f"{API_BASE}/context_nodes/", json={
"content": f"Project Context: Pixelle-Video\n\n{description}"
})
if resp.status_code == 200:
print(f"Context Node Created: {resp.json().get('id')}")
else:
print(f"Failed to create Context Node: {resp.status_code} {resp.text}")
except Exception as e:
print(f"Error creating Context Node: {e}")
# 3. Ingest Signal
print("Ingesting Project Signal...")
try:
resp = await client.post(f"{API_BASE}/signals/ingest", json={
"source": "System Integration",
"content": f"New Project Detected: Pixelle-Video. Path: {PIXELLE_PATH}. Status: Active Development. Requires strategic assessment and task breakdown.",
"impact_score": 0.95
})
if resp.status_code == 200:
data = resp.json()
print(f"Signal Ingested: {data.get('id')}")
print(f"Strategic Analysis: {data.get('decision_proposal')}")
print(f"Tasks Generated: {data.get('tasks_generated')}")
else:
print(f"Failed to ingest signal: {resp.text}")
except Exception as e:
print(f"Error ingesting signal: {e}")
# 4. Simulate Git Webhook (Code Audit)
print("Simulating Code Audit...")
try:
# Get latest commit info
result = subprocess.run(
["git", "log", "-1", "--pretty=format:%H|%s|%an"],
cwd=PIXELLE_PATH,
capture_output=True,
text=True
)
if result.returncode == 0:
commit_hash, commit_msg, author = result.stdout.split("|")
# Get diff (mocking generic diff)
diff_result = subprocess.run(
["git", "show", commit_hash],
cwd=PIXELLE_PATH,
capture_output=True,
text=True
)
diff = diff_result.stdout[:2000] # Limit diff size
payload = {
"commits": [
{
"id": commit_hash,
"message": f"{commit_msg} #PV-INIT", # Add fake task ID to trigger audit
"author": {"name": author},
"modified": ["various files"],
"patch": diff
}
],
"repository": {"name": "Pixelle-Video"}
}
resp = await client.post(f"{API_BASE}/webhooks/git", json=payload)
if resp.status_code == 200:
print(f"Webhook Processed: {resp.json()}")
else:
print(f"Webhook Failed: {resp.text}")
else:
print("Failed to get git log from Pixelle-Video")
except Exception as e:
print(f"Error simulating webhook: {e}")
if __name__ == "__main__":
asyncio.run(main())