- static/index.html: reduced to 127-line HTML shell - static/style.css: all styles extracted (~900 lines) + help modal styles + shared markdown rendering for file-preview and help-modal-body including tables (previously missing) - static/app.js: all JS extracted (~900 lines) + help modal fetch/render - index.html: adds ? help button + help modal HTML - inara/HELP.md: comprehensive reference doc covering all features, keyboard shortcuts, API endpoints, memory system, planned items - routers/files.py: HELP.md added to ALLOWED set - context_loader.py: HELP.md loaded at tier 2+ (after PROTOCOLS.md) so Inara can reference it when helping Scott with the interface Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
62 lines
1.5 KiB
Python
62 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",
|
|
"HELP.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)}
|