Reapply "Fix Assist to use mailbox system instead of direct 'in' file writes"

This reverts commit 8a9ce2c9e1.
This commit is contained in:
Levi Neely 2026-02-17 14:50:10 +01:00
parent 8a9ce2c9e1
commit 27f6a48411
1 changed files with 46 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"anvillm/internal/sandbox"
"encoding/json"
"flag"
"fmt"
"log"
@ -354,6 +355,42 @@ func sendPrompt(id, prompt string) error {
if !isConnected() {
return fmt.Errorf("not connected to anvilsrv")
}
// Create message JSON
msg := map[string]interface{}{
"to": id,
"type": "PROMPT",
"subject": "User prompt",
"body": prompt,
}
msgJSON, err := json.Marshal(msg)
if err != nil {
return fmt.Errorf("failed to marshal message: %w", err)
}
// Write to user outbox
timestamp := time.Now().Unix()
filename := fmt.Sprintf("msg-%d.json", timestamp)
path := filepath.Join("user/outbox", filename)
fid, err := fs.Create(path, plan9.OWRITE, 0644)
if err != nil {
return fmt.Errorf("failed to create message file: %w", err)
}
defer fid.Close()
_, err = fid.Write(msgJSON)
if err != nil {
return fmt.Errorf("failed to write message: %w", err)
}
return nil
}
func sendPromptDirect(id, prompt string) error {
if !isConnected() {
return fmt.Errorf("not connected to anvilsrv")
}
path := filepath.Join(id, "in")
fid, err := fs.Open(path, plan9.OWRITE)
if err != nil {
@ -570,8 +607,15 @@ func handlePromptWindow(w *acme.Win, sess *SessionInfo) {
}
prompt := strings.TrimSpace(string(body))
if prompt != "" {
if err := sendPrompt(sess.ID, prompt); err != nil {
fmt.Fprintf(os.Stderr, "Failed to send prompt: %v\n", err)
var sendErr error
if cmd == "Prompt" {
sendErr = sendPromptDirect(sess.ID, prompt)
} else {
sendErr = sendPrompt(sess.ID, prompt)
}
if sendErr != nil {
fmt.Fprintf(os.Stderr, "Failed to send %s: %v\n", strings.ToLower(cmd), sendErr)
continue
}
w.Ctl("delete")
return