mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-23 23:18:13 +02:00
feat(projets): racine active par contextvar + projet par session
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
25a88dd879
commit
8d0b57ad0d
5 files changed
+123
-16
No files matched your search
@@ -20,7 +20,7 @@ from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .. import agent_config, coder, db, enhance, memory, rag, skills
|
||||
from .. import agent_config, coder, db, enhance, memory, rag, skills, tools
|
||||
from .. import router as msg_router
|
||||
from ..tools import check_html, _safe_path
|
||||
from ..agent import run_agent
|
||||
@@ -87,7 +87,7 @@ def _session_code_context(history: list[dict]) -> tuple[str, list[str]]:
|
||||
et quelle demande d'origine. Les fichiers touchés servent aussi de cible
|
||||
par défaut pour Aider.
|
||||
"""
|
||||
root = os.path.abspath(settings.workspace_dir)
|
||||
root = tools.active_root()
|
||||
files: list[str] = []
|
||||
for m in history:
|
||||
if m["role"] != "assistant":
|
||||
@@ -121,8 +121,8 @@ def _session_code_context(history: list[dict]) -> tuple[str, list[str]]:
|
||||
|
||||
|
||||
def _workspace_listing(limit: int = 40) -> list[str]:
|
||||
"""Chemins relatifs des fichiers du workspace (aperçu compact)."""
|
||||
root = os.path.abspath(settings.workspace_dir)
|
||||
"""Chemins relatifs des fichiers de la racine active (aperçu compact)."""
|
||||
root = tools.active_root()
|
||||
out: list[str] = []
|
||||
for dirpath, dirnames, filenames in os.walk(root):
|
||||
dirnames[:] = [d for d in dirnames if not d.startswith(".")]
|
||||
@@ -145,7 +145,7 @@ def _mentioned_files(text: str) -> list[str]:
|
||||
Transmis au moteur code pour qu'Aider travaille directement sur les bons
|
||||
fichiers au lieu de deviner via la repo map.
|
||||
"""
|
||||
root = os.path.abspath(settings.workspace_dir)
|
||||
root = tools.active_root()
|
||||
out: list[str] = []
|
||||
for raw in _FILE_MENTION.findall(text):
|
||||
rel = raw.replace("\\", "/").lstrip("./")
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .. import db
|
||||
from .. import db, tools
|
||||
|
||||
router = APIRouter(prefix="/api/sessions", tags=["sessions"])
|
||||
|
||||
@@ -12,10 +12,12 @@ router = APIRouter(prefix="/api/sessions", tags=["sessions"])
|
||||
class CreateSession(BaseModel):
|
||||
title: str = "Nouvelle session"
|
||||
model: str | None = None
|
||||
project: str | None = None
|
||||
|
||||
|
||||
class RenameSession(BaseModel):
|
||||
title: str
|
||||
class UpdateSession(BaseModel):
|
||||
title: str | None = None
|
||||
project: str | None = None # "" = retour à la racine du workspace
|
||||
|
||||
|
||||
@router.get("")
|
||||
@@ -25,7 +27,9 @@ async def get_sessions() -> dict:
|
||||
|
||||
@router.post("")
|
||||
async def post_session(req: CreateSession) -> dict:
|
||||
return db.create_session(req.title, req.model)
|
||||
if req.project and not tools.PROJECT_NAME.match(req.project):
|
||||
raise HTTPException(400, "nom de projet invalide")
|
||||
return db.create_session(req.title, req.model, req.project or None)
|
||||
|
||||
|
||||
@router.get("/{sid}")
|
||||
@@ -37,10 +41,16 @@ async def get_one(sid: str) -> dict:
|
||||
|
||||
|
||||
@router.patch("/{sid}")
|
||||
async def patch_session(sid: str, req: RenameSession) -> dict:
|
||||
async def patch_session(sid: str, req: UpdateSession) -> dict:
|
||||
if not db.get_session(sid):
|
||||
raise HTTPException(404, "session introuvable")
|
||||
db.rename_session(sid, req.title)
|
||||
if req.title is not None:
|
||||
db.rename_session(sid, req.title)
|
||||
if req.project is not None:
|
||||
project = req.project or None
|
||||
if project and not tools.PROJECT_NAME.match(project):
|
||||
raise HTTPException(400, "nom de projet invalide")
|
||||
db.set_session_project(sid, project)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user