From 830849e193be3f63a785d4e511c0ae94c81e2130 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Fri, 24 Apr 2026 20:10:50 +0200 Subject: [PATCH] fix chat streaming and prompt writes - Return chat file as text/plain to preserve line ordering - Fix handleWrite: single-key JSON writes raw value, not key=value - Fixes broken chat display and 'prompt=' corruption in chat log --- main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 03f47b1..2887258 100644 --- a/main.go +++ b/main.go @@ -218,6 +218,11 @@ func handleRead(w http.ResponseWriter, fsys *client.Fsys, p string) { writeJSON(w, http.StatusOK, parseIdx(content)) return } + if path.Base(p) == "chat" { + w.Header().Set("Content-Type", "text/plain; charset=utf-8") + w.Write(content) + return + } writeJSON(w, http.StatusOK, parseContent(content, path.Base(p))) } @@ -318,12 +323,24 @@ func handleWrite(w http.ResponseWriter, r *http.Request, fsys *client.Fsys, p st writeJSON(w, http.StatusBadRequest, map[string]string{"error": err.Error()}) return } + // If the body has a single key matching the file name, write just the value. + // Otherwise serialize as key=value lines (e.g. for "new"). + var payload []byte + base := path.Base(p) + if len(m) == 1 { + if v, ok := m[base]; ok { + payload = []byte(fmt.Sprintf("%v", v)) + } + } + if payload == nil { + payload = serializeKV(m) + } fid, err := fsys.Open(p, plan9.OWRITE) if err != nil { writeJSON(w, http.StatusNotFound, map[string]string{"error": err.Error()}) return } - n, err := fid.Write(serializeKV(m)) + n, err := fid.Write(payload) fid.Close() if err != nil { writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})