kin: KIN-048 Post-pipeline hook: автокоммит после успешного завершения задачи. git add -A && git commit -m 'kin: TASK_ID TITLE'. Срабатывает автоматически как rebuild-frontend.
This commit is contained in:
parent
8a6f280cbd
commit
ae21e48b65
13 changed files with 1554 additions and 65 deletions
62
web/api.py
62
web/api.py
|
|
@ -3,6 +3,8 @@ Kin Web API — FastAPI backend reading ~/.kin/kin.db via core.models.
|
|||
Run: uvicorn web.api:app --reload --port 8420
|
||||
"""
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
|
@ -18,6 +20,7 @@ from pydantic import BaseModel
|
|||
|
||||
from core.db import init_db
|
||||
from core import models
|
||||
from core.models import VALID_COMPLETION_MODES
|
||||
from agents.bootstrap import (
|
||||
detect_tech_stack, detect_modules, extract_decisions_from_claude_md,
|
||||
find_vault_root, scan_obsidian, save_to_db,
|
||||
|
|
@ -25,6 +28,62 @@ from agents.bootstrap import (
|
|||
|
||||
DB_PATH = Path.home() / ".kin" / "kin.db"
|
||||
|
||||
_logger = logging.getLogger("kin")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Startup: verify claude CLI is available in PATH
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _check_claude_available() -> None:
|
||||
"""Warn at startup if claude CLI cannot be found in PATH.
|
||||
|
||||
launchctl daemons run with a stripped environment and may not see
|
||||
/opt/homebrew/bin where claude is typically installed.
|
||||
See Decision #28.
|
||||
"""
|
||||
from agents.runner import _build_claude_env # avoid circular import at module level
|
||||
env = _build_claude_env()
|
||||
claude_path = shutil.which("claude", path=env["PATH"])
|
||||
if claude_path:
|
||||
_logger.info("claude CLI found: %s", claude_path)
|
||||
else:
|
||||
_logger.warning(
|
||||
"WARNING: claude CLI not found in PATH (%s). "
|
||||
"Agent pipelines will fail with returncode 127. "
|
||||
"Fix: add /opt/homebrew/bin to EnvironmentVariables.PATH in "
|
||||
"~/Library/LaunchAgents/com.kin.api.plist and reload with: "
|
||||
"launchctl unload ~/Library/LaunchAgents/com.kin.api.plist && "
|
||||
"launchctl load ~/Library/LaunchAgents/com.kin.api.plist",
|
||||
env.get("PATH", ""),
|
||||
)
|
||||
|
||||
|
||||
def _check_git_available() -> None:
|
||||
"""Warn at startup if git cannot be found in PATH.
|
||||
|
||||
launchctl daemons run with a stripped environment and may not see
|
||||
git in the standard directories. See Decision #28.
|
||||
"""
|
||||
from agents.runner import _build_claude_env # avoid circular import at module level
|
||||
env = _build_claude_env()
|
||||
git_path = shutil.which("git", path=env["PATH"])
|
||||
if git_path:
|
||||
_logger.info("git found: %s", git_path)
|
||||
else:
|
||||
_logger.warning(
|
||||
"WARNING: git not found in PATH (%s). "
|
||||
"Autocommit will fail silently. "
|
||||
"Fix: add git directory to EnvironmentVariables.PATH in "
|
||||
"~/Library/LaunchAgents/com.kin.api.plist and reload with: "
|
||||
"launchctl unload ~/Library/LaunchAgents/com.kin.api.plist && "
|
||||
"launchctl load ~/Library/LaunchAgents/com.kin.api.plist",
|
||||
env.get("PATH", ""),
|
||||
)
|
||||
|
||||
|
||||
_check_claude_available()
|
||||
_check_git_available()
|
||||
|
||||
app = FastAPI(title="Kin API", version="0.1.0")
|
||||
|
||||
app.add_middleware(
|
||||
|
|
@ -162,7 +221,7 @@ class TaskPatch(BaseModel):
|
|||
|
||||
|
||||
VALID_STATUSES = set(models.VALID_TASK_STATUSES)
|
||||
VALID_EXECUTION_MODES = {"auto", "review"}
|
||||
VALID_EXECUTION_MODES = VALID_COMPLETION_MODES
|
||||
|
||||
|
||||
@app.patch("/api/tasks/{task_id}")
|
||||
|
|
@ -361,6 +420,7 @@ def run_task(task_id: str):
|
|||
cmd,
|
||||
cwd=str(kin_root),
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stdin=subprocess.DEVNULL,
|
||||
env=env,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue