Add service status and usage dashboard, refresh externally published edits

This commit is contained in:
2026-10-09 20:20:44 +01:00
parent 67ac79765f
commit a50e8648f6
31 changed files with 1283 additions and 42 deletions
+56
View File
@@ -19,6 +19,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/runinspect"
"git.a-wan.net/alan/pipelines/internal/statusview"
"git.a-wan.net/alan/pipelines/internal/tui"
tea "github.com/charmbracelet/bubbletea"
)
@@ -238,6 +239,17 @@ func (a App) Run(ctx context.Context, args []string) error {
c, err := client.Open(dialCtx, o.url)
cancel()
if err != nil {
if command == "status" && len(pos) == 0 {
s := statusview.Offline(o.url)
if o.json {
if outputErr := a.output(s); outputErr != nil {
return outputErr
}
} else {
fmt.Fprintln(a.Out, strings.Join(statusview.Lines(s), "\n"))
}
return fmt.Errorf("Pipelines server unavailable")
}
return err
}
defer c.Close()
@@ -272,6 +284,50 @@ func (a App) Run(ctx context.Context, args []string) error {
return pos[0], nil
}
switch command {
case "stats":
if len(pos) != 0 {
return fmt.Errorf("stats takes no arguments")
}
response, err := call(protocol.Message{Type: protocol.ListRuns})
if err != nil {
return err
}
if response.Usage == nil {
return fmt.Errorf("server did not return usage statistics; update pipelines-server")
}
if o.json {
return a.output(response.Usage)
}
u := response.Usage
average := "—"
if u.Total > u.Active {
average = time.Duration(u.AverageSeconds * float64(time.Second)).Round(time.Second).String()
}
fmt.Fprintf(a.Out, "Usage · all history\n%d runs · %d succeeded · %d failed · %d canceled · %d interrupted · %d active\nAverage completed duration: %s\n\nPipeline\tRuns\tSucceeded\tFailed\tActive\n", u.Total, u.Succeeded, u.Failed, u.Canceled, u.Interrupted, u.Active, average)
for _, p := range u.Pipelines {
fmt.Fprintf(a.Out, "%s\t%d\t%d\t%d\t%d\n", p.Name, p.Total, p.Succeeded, p.Failed, p.Active)
}
fmt.Fprintln(a.Out, "\nDaily activity (UTC)")
for _, d := range u.Days {
fmt.Fprintf(a.Out, "%s\t%d\n", d.Date, d.Runs)
}
return nil
case "status":
if len(pos) != 0 {
return fmt.Errorf("status takes no arguments")
}
response, err := call(protocol.Message{Type: protocol.GetStatus})
if err != nil {
return err
}
if response.Status == nil {
return fmt.Errorf("server did not return status; update pipelines-server")
}
if o.json {
return a.output(response.Status)
}
_, err = fmt.Fprintln(a.Out, strings.Join(statusview.Lines(response.Status), "\n"))
return err
case "debug":
value, err := one()
if err != nil {
+33
View File
@@ -53,6 +53,39 @@ func TestCLIHelpDoesNotNeedServer(t *testing.T) {
}
}
func TestCLIStatusAndStatistics(t *testing.T) {
t.Setenv("PIPELINES_NTFY_URL", "")
run, _, _ := setup(t)
output, err := run("status")
if err != nil {
t.Fatal(err)
}
for _, text := range []string{"Pipelines server", "ntfy", "not configured", "Server computer IPs", "Port:"} {
if !strings.Contains(output, text) {
t.Fatal("missing CLI status", text, output)
}
}
output, err = run("status", "--json")
if err != nil {
t.Fatal(err)
}
var status protocol.SystemStatus
if err := json.Unmarshal([]byte(output), &status); err != nil || status.Server.Health != "healthy" || status.Server.Port == "" {
t.Fatal(output, err)
}
output, err = run("stats", "--json")
if err != nil {
t.Fatal(err)
}
var usage protocol.UsageStats
if err := json.Unmarshal([]byte(output), &usage); err != nil || usage.Total != 0 || len(usage.Days) != 14 {
t.Fatal(output, err)
}
if _, err := run("status", "extra"); err == nil {
t.Fatal("status accepted extra positional")
}
}
func TestCLIDraftValidateSubmitAndImmutableHistory(t *testing.T) {
run, store, _ := setup(t)
output, err := run("new", "example", "--template", "bug-fix", "--json")
+2 -1
View File
@@ -22,6 +22,8 @@ var usage = map[string]string{
"debug": "debug <run-id> [--json | --no-open]",
"connection": "connection [--json]",
"ping": "ping [--json]",
"status": "status [--json]",
"stats": "stats [--json]",
"rpc": "rpc <request.json|->",
"tui": "tui",
}
@@ -44,7 +46,6 @@ var serviceHelp = map[string]string{
"start": "Start the per-user native pipeline server and this installation's Docker ntfy together.",
"stop": "Stop both services. Active execution is interrupted; file changes are not rolled back.",
"restart": "Stop, then start both services, retaining definitions, run history, and credentials.",
"status": "Show pipeline/ntfy health and the public phone connection (no credentials).",
"doctor": "Check both health endpoints and host OpenCode API discovery; does not execute a model.",
"logs": "Follow the native server log. Press Ctrl+C to stop following.",
"uninstall": "Remove verified Go binaries from this command's bin directory; retain data and drafts. --yes skips confirmation. Existing managed installations can be selected explicitly with PIPELINES_PREFIX.",
+3 -1
View File
@@ -28,6 +28,8 @@ EXECUTE
debug <run-id> Ask OpenCode questions about a recorded or active run
draft-delete <draft.md> Delete a selected retained draft and its metadata
connection Server and public phone connection (no secrets)
status Server/ntfy health, ports and server computer IPs
stats All-history usage, pipeline counts and daily activity
ping Check the server connection
rpc <request.json|-> Send any protocol command (automation escape hatch)
@@ -40,7 +42,7 @@ SERVER / INTERFACE
uninstall [--yes] Remove verified Go binaries; retain data and drafts
Legacy managed installs: select PIPELINES_PREFIX explicitly for start/stop,
restart/status/doctor/logs and retained-data or --purge uninstallation.
restart/doctor/logs and retained-data or --purge uninstallation.
Options: --url ws://127.0.0.1:8080/connect --json --help
Use pipelines help <command> for its flags. Names with spaces must be quoted.