e79ff9585f
Each completed step now exposes a verdict: the chosen option (outcome -> target), a bounded one-line reason with model/fallback/absent provenance, and the recorded artifacts the reason refers to. The store persists only the model-generated line in a new step_verdicts table and derives the fallback at read time (no backfill); the server generates the line once at completion, best-effort; the TUI renders it in the stage progress summary. The packaged debugging reference documents it.
78 lines
2.8 KiB
Go
78 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"path/filepath"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/opencode"
|
|
"git.a-wan.net/alan/pipelines/internal/paths"
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/server"
|
|
"git.a-wan.net/alan/pipelines/internal/summarise"
|
|
)
|
|
|
|
func main() {
|
|
addr := flag.String("addr", "127.0.0.1:8080", "HTTP/WebSocket listen address")
|
|
defaultDB, err := paths.Database()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
db := flag.String("db", defaultDB, "SQLite database path (honors XDG_DATA_HOME)")
|
|
flag.Parse()
|
|
if err := os.MkdirAll(filepath.Dir(*db), 0700); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
store, err := pipeline.Open(*db)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
artifactsRoot := filepath.Join(filepath.Dir(*db), "artifacts")
|
|
// Each new run gets a bounded one-line title from the configured default
|
|
// harness; the summariser falls back to the prompt's first line, so title
|
|
// generation never blocks or fails run creation.
|
|
options := server.Options{ArtifactsRoot: artifactsRoot, RunTitles: summarise.GenerateTitle, StepVerdicts: summarise.GenerateVerdictReason}
|
|
// Chat brokers OpenCode over the owned endpoint. Streaming needs a
|
|
// URL-bearing, SSE-capable backend. Detect may select "v2" (the CLI
|
|
// advertises `api`), but Open never starts a serve process for v2 and so
|
|
// returns no event-stream URL: this build enables chat only when a
|
|
// connection carries a streamable endpoint (the owned v1 serve process).
|
|
// Otherwise chat stays disabled and every chat_* request is answered with a
|
|
// protocol error naming the missing configuration rather than hanging.
|
|
if backend, err := opencode.Detect(ctx, opencode.Executable()); err != nil {
|
|
log.Printf("OpenCode chat unavailable: %v", err)
|
|
} else if conn, err := opencode.Open(ctx, opencode.Executable(), "", backend); err != nil {
|
|
log.Printf("OpenCode chat unavailable: %v", err)
|
|
} else if conn.URL == "" {
|
|
conn.Close()
|
|
log.Printf("OpenCode chat unavailable: backend %q exposes no streamable event endpoint", backend)
|
|
} else {
|
|
options.Chat = opencode.NewChat(conn)
|
|
defer conn.Close()
|
|
}
|
|
srv := &http.Server{Addr: *addr, Handler: server.HandlerWithOptions(ctx, options, store), ReadHeaderTimeout: 5 * time.Second}
|
|
defer server.WaitRuns(srv.Handler)
|
|
go func() {
|
|
<-ctx.Done()
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
if err := srv.Shutdown(shutdownCtx); err != nil {
|
|
log.Printf("shutdown: %v", err)
|
|
}
|
|
}()
|
|
log.Printf("listening on %s (WebSocket endpoint: /connect)", *addr)
|
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
log.Fatal(err)
|
|
}
|
|
}
|