open read-only access to /a, /m, /t, /sk; preserve blank lines

- Allow GET/HEAD on agent, memory, tool, skill paths
- Preserve empty lines in multi-line file content
This commit is contained in:
Levi Neely 2026-04-24 21:13:41 +02:00
parent 830849e193
commit 14bcbf0646
1 changed files with 11 additions and 4 deletions

15
main.go
View File

@ -105,11 +105,20 @@ func handler(w http.ResponseWriter, r *http.Request) {
// Internal paths not exposed via HTTP.
first, _, _ := strings.Cut(p, "/")
// Paths never exposed via HTTP.
switch first {
case "", "a", "p", "m", "t", "sk", "help", "tr", "u", "x", "tmp":
case "p", "help", "tr", "u", "x", "tmp":
writeJSON(w, http.StatusNotFound, map[string]string{"error": "not found"})
return
}
// Read-only paths — only GET and HEAD allowed.
switch first {
case "", "a", "m", "t", "sk":
if r.Method != http.MethodGet && r.Method != http.MethodHead {
writeJSON(w, http.StatusMethodNotAllowed, map[string]string{"error": "read-only"})
return
}
}
base := path.Base(p)
switch base {
case "systemprompt", "statewait":
@ -288,9 +297,7 @@ func parseContent(data []byte, name string) any {
}
var lines []string
for line := range strings.SplitSeq(s, "\n") {
if line != "" {
lines = append(lines, line)
}
lines = append(lines, line)
}
if len(lines) == 1 {
return map[string]string{name: lines[0]}