- config.py: memory_budget_long/mid/short settings (overridable in .env)
- memory_distiller.py: distill_short (no LLM), distill_mid, distill_long (LLM)
- routers/distill.py: POST /distill/{short,mid,long,all} endpoints
- context_loader.py: rewrote to load long→mid→short order with include_* toggles
- routers/chat.py: ChatRequest gains include_long/mid/short fields
- routers/files.py: MEMORY_LONG/MID/SHORT.md added to ALLOWED set
- main.py: register distill router
- static/index.html: context bar — tier selector, L/M/S memory toggles,
distill buttons with status feedback; send includes tier + memory flags
- inara/MEMORY_LONG.md: migrated from MEMORY.md + Cortex/Talk bot notes
- inara/MEMORY_MID.md, MEMORY_SHORT.md: stubs ready for distillation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""
|
|
Read/write the Inara identity markdown files.
|
|
Only whitelisted filenames are accessible — no path traversal possible.
|
|
"""
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
from config import settings
|
|
|
|
router = APIRouter()
|
|
|
|
ALLOWED = {
|
|
"SOUL.md",
|
|
"IDENTITY.md",
|
|
"USER.md",
|
|
"PROTOCOLS.md",
|
|
"CONTEXT_TIERS.md",
|
|
"MEMORY.md", # legacy — kept for reference
|
|
"MEMORY_LONG.md",
|
|
"MEMORY_MID.md",
|
|
"MEMORY_SHORT.md",
|
|
}
|
|
|
|
|
|
def _path(filename: str):
|
|
if filename not in ALLOWED:
|
|
raise HTTPException(status_code=404, detail=f"File not found: {filename}")
|
|
return settings.inara_path() / filename
|
|
|
|
|
|
@router.get("/files")
|
|
async def list_files() -> dict:
|
|
inara_dir = settings.inara_path()
|
|
files = []
|
|
for name in sorted(ALLOWED):
|
|
p = inara_dir / name
|
|
files.append({
|
|
"name": name,
|
|
"exists": p.exists(),
|
|
"size": p.stat().st_size if p.exists() else 0,
|
|
})
|
|
return {"files": files}
|
|
|
|
|
|
@router.get("/files/{filename}")
|
|
async def get_file(filename: str) -> dict:
|
|
p = _path(filename)
|
|
if not p.exists():
|
|
raise HTTPException(status_code=404, detail=f"{filename} does not exist")
|
|
return {"name": filename, "content": p.read_text()}
|
|
|
|
|
|
class FileWrite(BaseModel):
|
|
content: str
|
|
|
|
|
|
@router.put("/files/{filename}")
|
|
async def save_file(filename: str, req: FileWrite) -> dict:
|
|
p = _path(filename)
|
|
p.write_text(req.content)
|
|
return {"ok": True, "name": filename, "size": len(req.content)}
|