fix template, remove okr, use casan.*

This commit is contained in:
thanhnv
2026-07-18 16:45:31 +07:00
parent 0dfd1742d3
commit 13fae3e6c3
249 changed files with 4881 additions and 5702 deletions
@@ -1,11 +1,14 @@
#!/usr/bin/env python3
"""Apply an approved Goal patch with bounded paths and rollback-on-failure."""
from __future__ import annotations
import argparse
import hashlib
import json
import os
import subprocess
import tempfile
import importlib.util
from datetime import datetime, timezone
@@ -20,6 +23,12 @@ def root() -> str:
ROOT = root()
INBOX = os.path.join(ROOT, "packages", "casan-harness", "scripts", "bash", "approval-inbox.py")
_MANIFEST_SPEC = importlib.util.spec_from_file_location(
"casan_project_manifest",
os.path.join(os.path.dirname(__file__), "project_manifest.py"),
)
PROJECT_MANIFEST = importlib.util.module_from_spec(_MANIFEST_SPEC)
_MANIFEST_SPEC.loader.exec_module(PROJECT_MANIFEST)
def now() -> str:
@@ -62,15 +71,33 @@ def verify_approval(job: dict) -> dict:
return proposal
def verification_commands(files: list[str]) -> list[list[str]]:
commands = [["git", "diff", "--check", "--", *files]]
if any(path.startswith("apps/okr/frontend/") for path in files):
commands.append(["npm", "run", "build", "-w", "@ainative-okr/frontend"])
commands.append(["npm", "test", "-w", "@ainative-okr/frontend"])
if any(path.startswith("apps/okr/backend/") for path in files):
commands.append(["npm", "run", "build", "-w", "@ainative-okr/backend"])
commands.append(["npm", "test", "-w", "@ainative-okr/backend"])
return commands
def _manifest_for_files(files: list[str]) -> dict:
selected = os.environ.get("CASAN_PROJECT_MANIFEST")
project = os.environ.get("CASAN_PROJECT_ID")
if selected or project:
return PROJECT_MANIFEST.load(ROOT, selected, project)
registry = load(os.path.join(ROOT, "packages", "casan-harness", "level5", "project-registry.json"))
candidates = []
for entry in registry.get("projects", []):
manifest_path = entry.get("manifest")
if not manifest_path or entry.get("status") != "active":
continue
try:
manifest = PROJECT_MANIFEST.load(ROOT, manifest_path)
except (OSError, ValueError):
continue
if any(any(path.startswith(root.rstrip("/") + "/") for root in manifest["source_roots"]) for path in files):
candidates.append(manifest)
if len(candidates) != 1:
reason = "none" if not candidates else "multiple"
raise RuntimeError(f"GOAL_APPLY_PROJECT_MANIFEST_{reason.upper()}")
return candidates[0]
def verification_commands(files: list[str], manifest: dict | None = None) -> list[list[str]]:
project = manifest or _manifest_for_files(files)
return [["git", "diff", "--check", "--", *files], *PROJECT_MANIFEST.verification_commands(project, files)]
def execute(job_path: str, actor: str) -> dict: