web: run pipelines from the browser and quiet background chat
Add the Run pipeline dialog with prompt, server directory and a per-run notification choice; add --notify auto/on/off to run and retry; move the live tool call onto the tool-count line and tick the reasoning duration; stop chat frames from repainting a different screen.
This commit is contained in:
+22
-4
@@ -37,7 +37,7 @@ type options struct {
|
||||
harness string
|
||||
url, name, prompt, title, template, workspace, paths, key, opencode, model string
|
||||
retryMode, retryStage, retryInputFile string
|
||||
option, feedback, evidence, actor string
|
||||
option, feedback, evidence, actor, notifyMode string
|
||||
output string
|
||||
conflict string
|
||||
kind string
|
||||
@@ -146,6 +146,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.StringVar(&o.key, "request-key", "", "Idempotency key (default: generated unique key)")
|
||||
f.IntVar(&o.version, "version", 0, "Version to run (default: latest)")
|
||||
f.StringVar(&o.model, "model", "", "Override the model for every stage of this run (PROVIDER/MODEL)")
|
||||
f.StringVar(&o.notifyMode, "notify", "auto", "Notifications for this run: auto (pipeline), on, or off")
|
||||
o.stageModels = stageModelFlags{}
|
||||
f.Var(o.stageModels, "stage-model", "Override one stage's model; repeatable (STAGE=PROVIDER/MODEL); beats --model")
|
||||
f.BoolVar(&o.wait, "wait", false, "In JSON mode, wait for a terminal run state")
|
||||
@@ -165,6 +166,7 @@ func (a App) flags(command string) (*flag.FlagSet, *options) {
|
||||
f.IntVar(&o.retryVisit, "visit", 0, "1-based occurrence of --stage in the recorded execution")
|
||||
f.IntVar(&o.version, "version", 0, "Explicit published version of the same pipeline (default: source version)")
|
||||
f.StringVar(&o.retryInputFile, "input-file", "", "JSON object merged into the selected stage input; '-' reads stdin")
|
||||
f.StringVar(&o.notifyMode, "notify", "auto", "Notifications for this retry: auto, on, or off")
|
||||
case "cancel", "draft-delete":
|
||||
f.BoolVar(&o.yes, "yes", false, "Confirm this action without an interactive prompt")
|
||||
case "retention":
|
||||
@@ -930,6 +932,14 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if o.retryMode != "resume" && o.retryMode != "restart" {
|
||||
return fmt.Errorf("--mode must be resume or restart")
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(o.notifyMode)) {
|
||||
case "", "auto":
|
||||
o.notifyMode = "auto"
|
||||
case "on", "off":
|
||||
o.notifyMode = strings.ToLower(strings.TrimSpace(o.notifyMode))
|
||||
default:
|
||||
return fmt.Errorf("--notify must be auto, on or off")
|
||||
}
|
||||
if key == "" {
|
||||
key = fmt.Sprintf("retry-%d-%d", os.Getpid(), time.Now().UnixNano())
|
||||
}
|
||||
@@ -966,7 +976,7 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if o.retryVisit < 0 {
|
||||
return fmt.Errorf("--visit must be positive")
|
||||
}
|
||||
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput})
|
||||
r, err := call(protocol.Message{Type: typeName, RunID: id, RequestKey: key, RetryMode: o.retryMode, RetryStage: o.retryStage, RetryVisit: o.retryVisit, RetryVersion: o.version, RetryInput: retryInput, NotifyMode: o.notifyMode})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1277,6 +1287,14 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
|
||||
return err
|
||||
}
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(o.notifyMode)) {
|
||||
case "", "auto":
|
||||
o.notifyMode = "auto"
|
||||
case "on", "off":
|
||||
o.notifyMode = strings.ToLower(strings.TrimSpace(o.notifyMode))
|
||||
default:
|
||||
return fmt.Errorf("--notify must be auto, on or off")
|
||||
}
|
||||
if o.yes && (o.name == "" || strings.TrimSpace(o.prompt) == "") {
|
||||
return fmt.Errorf("--yes requires a pipeline and nonempty prompt")
|
||||
}
|
||||
@@ -1291,7 +1309,7 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
|
||||
if o.wait || o.key != "" || o.version > 0 {
|
||||
return fmt.Errorf("--wait, --request-key and --version require --json")
|
||||
}
|
||||
_, err := tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Title: o.title, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels}), tea.WithContext(ctx), tea.WithAltScreen()).Run()
|
||||
_, err := tea.NewProgram(tui.NewRun(ctx, o.url, tui.RunOptions{Pipeline: o.name, Prompt: o.prompt, Title: o.title, Workspace: workspace, Yes: o.yes, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode}), tea.WithContext(ctx), tea.WithAltScreen()).Run()
|
||||
return err
|
||||
}
|
||||
if o.name == "" || strings.TrimSpace(o.prompt) == "" {
|
||||
@@ -1313,7 +1331,7 @@ func (a App) run(ctx context.Context, pos []string, o *options, call callFunc, r
|
||||
if key == "" {
|
||||
key = fmt.Sprintf("cli-%d-%d", os.Getpid(), time.Now().UnixNano())
|
||||
}
|
||||
r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Title: o.title, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels})
|
||||
r, err := call(protocol.Message{Type: protocol.RunPipeline, PipelineID: p.ID, Version: version, RequestKey: key, Workspace: workspace, Title: o.title, Input: map[string]any{"prompt": o.prompt}, AllowTools: o.allow, WritePaths: paths, Model: o.model, StageModels: o.stageModels, NotifyMode: o.notifyMode})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ import (
|
||||
type RunOverrides struct {
|
||||
Model string
|
||||
StageModels map[string]string
|
||||
// NotifyMode is auto, on or off for this run. Empty means auto.
|
||||
NotifyMode string
|
||||
}
|
||||
|
||||
// CreateRun inserts a run and derives its title from the prompt. It is the entry
|
||||
@@ -61,15 +63,15 @@ func (s *Store) CreateRunTitled(ctx context.Context, d *protocol.PipelineDetail,
|
||||
defer s.mu.Unlock()
|
||||
var id, pid int64
|
||||
var version int
|
||||
var oldInput, oldWorkspace, oldPaths, oldModel, oldStageModels string
|
||||
var oldInput, oldWorkspace, oldPaths, oldModel, oldStageModels, oldNotify string
|
||||
var oldTools bool
|
||||
err = s.db.QueryRowContext(ctx, "SELECT id,pipeline_id,version,input_json,workspace,write_paths,allow_tools,model,stage_models FROM pipeline_runs WHERE request_key=?", key).Scan(&id, &pid, &version, &oldInput, &oldWorkspace, &oldPaths, &oldTools, &oldModel, &oldStageModels)
|
||||
err = s.db.QueryRowContext(ctx, "SELECT id,pipeline_id,version,input_json,workspace,write_paths,allow_tools,model,stage_models,notify_mode FROM pipeline_runs WHERE request_key=?", key).Scan(&id, &pid, &version, &oldInput, &oldWorkspace, &oldPaths, &oldTools, &oldModel, &oldStageModels, &oldNotify)
|
||||
if err == nil {
|
||||
var oldParent int64
|
||||
if err := s.db.QueryRowContext(ctx, "SELECT COALESCE((SELECT original_run_id FROM run_retries WHERE run_id=?),0)", id).Scan(&oldParent); err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
if pid != d.ID || version != d.Version || oldInput != string(encoded) || oldWorkspace != workspace || oldPaths != string(writes) || oldTools != tools || oldParent != parent || oldModel != overrides.Model || oldStageModels != string(encodedModels) {
|
||||
if pid != d.ID || version != d.Version || oldInput != string(encoded) || oldWorkspace != workspace || oldPaths != string(writes) || oldTools != tools || oldParent != parent || oldModel != overrides.Model || oldStageModels != string(encodedModels) || oldNotify != notifyMode(overrides.NotifyMode) {
|
||||
return 0, false, fmt.Errorf("request key already used for a different run")
|
||||
}
|
||||
return id, false, nil
|
||||
@@ -82,7 +84,7 @@ func (s *Store) CreateRunTitled(ctx context.Context, d *protocol.PipelineDetail,
|
||||
return 0, false, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
result, err := tx.ExecContext(ctx, "INSERT INTO pipeline_runs(pipeline_id,version,request_key,workspace,allow_tools,write_paths,input_json,title,title_source,title_model,model,stage_models) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", d.ID, d.Version, key, workspace, tools, string(writes), string(encoded), title.Text, title.Source, title.Model, overrides.Model, string(encodedModels))
|
||||
result, err := tx.ExecContext(ctx, "INSERT INTO pipeline_runs(pipeline_id,version,request_key,workspace,allow_tools,write_paths,input_json,title,title_source,title_model,model,stage_models,notify_mode) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", d.ID, d.Version, key, workspace, tools, string(writes), string(encoded), title.Text, title.Source, title.Model, overrides.Model, string(encodedModels), notifyMode(overrides.NotifyMode))
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
@@ -101,6 +103,26 @@ func (s *Store) CreateRunTitled(ctx context.Context, d *protocol.PipelineDetail,
|
||||
return id, true, nil
|
||||
}
|
||||
|
||||
func notifyMode(value string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "on", "off":
|
||||
return strings.ToLower(strings.TrimSpace(value))
|
||||
default:
|
||||
return "auto"
|
||||
}
|
||||
}
|
||||
|
||||
// RunNotifyMode returns the stored per-run notification override (auto, on or
|
||||
// off). It lets a restarted server honor an existing run's silence.
|
||||
func (s *Store) RunNotifyMode(ctx context.Context, id int64) (string, error) {
|
||||
var mode string
|
||||
err := s.db.QueryRowContext(ctx, "SELECT notify_mode FROM pipeline_runs WHERE id=?", id).Scan(&mode)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return notifyMode(mode), nil
|
||||
}
|
||||
|
||||
// resolveRunTitle guarantees a stored run title is never empty: a title supplied
|
||||
// by the caller (a model generation) is kept verbatim, and an absent one is
|
||||
// derived from the prompt's first line. The fallback is server-owned and never
|
||||
|
||||
@@ -12,7 +12,7 @@ func (s *Store) initRuns() error {
|
||||
id INTEGER PRIMARY KEY, pipeline_id INTEGER NOT NULL, version INTEGER NOT NULL,
|
||||
request_key TEXT NOT NULL UNIQUE, workspace TEXT NOT NULL, allow_tools INTEGER NOT NULL,
|
||||
title TEXT NOT NULL DEFAULT '', title_source TEXT NOT NULL DEFAULT '', title_model TEXT NOT NULL DEFAULT '',
|
||||
model TEXT NOT NULL DEFAULT '', stage_models TEXT NOT NULL DEFAULT '{}',
|
||||
model TEXT NOT NULL DEFAULT '', stage_models TEXT NOT NULL DEFAULT '{}', notify_mode TEXT NOT NULL DEFAULT 'auto',
|
||||
write_paths TEXT NOT NULL, input_json TEXT NOT NULL, output_json TEXT NOT NULL DEFAULT '{}',
|
||||
status TEXT NOT NULL DEFAULT 'queued', outcome TEXT NOT NULL DEFAULT '', current_stage TEXT NOT NULL DEFAULT '',
|
||||
diagnostic TEXT NOT NULL DEFAULT '', created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, finished_at TEXT,
|
||||
@@ -62,6 +62,9 @@ CREATE TABLE IF NOT EXISTS retry_checkpoints (
|
||||
if err := s.migrateRunTitles(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.addColumnIfMissing("pipeline_runs", "notify_mode", "TEXT NOT NULL DEFAULT 'auto'"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.dropResourceSchema(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -153,6 +153,9 @@ type Message struct {
|
||||
// them; the same fields are echoed on the run record.
|
||||
Model string `json:"model,omitempty"`
|
||||
StageModels map[string]string `json:"stage_models,omitempty"`
|
||||
// NotifyMode is auto (definition), on (ensure run-level attention) or off
|
||||
// (silence this run). It is optional so older clients keep auto.
|
||||
NotifyMode string `json:"notify_mode,omitempty"`
|
||||
// Empty (or "resume") retries the failed visit; "restart" starts at the
|
||||
// entry stage. Older clients omit this field and retain resume behavior.
|
||||
RetryMode string `json:"retry_mode,omitempty"`
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.NotificationPolicy, step protocol.RunStep) {
|
||||
if policy == nil {
|
||||
if r.notifyMode(id) == "off" || policy == nil {
|
||||
return
|
||||
}
|
||||
event := "success"
|
||||
@@ -183,6 +183,40 @@ func (r *runner) attentionAlready(id int64, sequence int, event string) bool {
|
||||
return r.attentionSent[id][fmt.Sprintf("%d:%s", sequence, event)]
|
||||
}
|
||||
|
||||
func (r *runner) setNotifyMode(id int64, mode string) {
|
||||
mode = strings.ToLower(strings.TrimSpace(mode))
|
||||
if mode != "on" && mode != "off" {
|
||||
mode = "auto"
|
||||
}
|
||||
r.notifyMu.Lock()
|
||||
r.notifyModes[id] = mode
|
||||
r.notifyMu.Unlock()
|
||||
}
|
||||
|
||||
func (r *runner) notifyMode(id int64) string {
|
||||
r.notifyMu.Lock()
|
||||
mode := r.notifyModes[id]
|
||||
r.notifyMu.Unlock()
|
||||
if mode != "" {
|
||||
return mode
|
||||
}
|
||||
if r.store != nil {
|
||||
if stored, err := r.store.RunNotifyMode(r.ctx, id); err == nil && stored != "" {
|
||||
r.notifyMu.Lock()
|
||||
r.notifyModes[id] = stored
|
||||
r.notifyMu.Unlock()
|
||||
return stored
|
||||
}
|
||||
}
|
||||
return "auto"
|
||||
}
|
||||
|
||||
func (r *runner) forgetNotifyMode(id int64) {
|
||||
r.notifyMu.Lock()
|
||||
delete(r.notifyModes, id)
|
||||
r.notifyMu.Unlock()
|
||||
}
|
||||
|
||||
// forgetAttention drops a run's delivered-event set once it is terminal, so the
|
||||
// registry is bounded by the runs still in flight.
|
||||
func (r *runner) forgetAttention(id int64) {
|
||||
@@ -206,6 +240,9 @@ func runAttentionClick(id int64) string {
|
||||
// A run that needs nobody produces nothing, and a delivery failure is logged and
|
||||
// never fails the run: this is a best-effort alert, not persisted run evidence.
|
||||
func (r *runner) notifyRun(id int64, name, status string, sequence int, currentStage, diagnostic string) {
|
||||
if r.notifyMode(id) == "off" {
|
||||
return
|
||||
}
|
||||
event := runAttentionEvent(status)
|
||||
if event == "" {
|
||||
return
|
||||
|
||||
@@ -70,6 +70,10 @@ type runner struct {
|
||||
// default — so neither republishes the same genuine event.
|
||||
attentionMu sync.Mutex
|
||||
attentionSent map[int64]map[string]bool
|
||||
// notifyMu guards notifyModes: the per-run auto/on/off override recorded at
|
||||
// admission. It is separate from the stage's own notify policy.
|
||||
notifyMu sync.Mutex
|
||||
notifyModes map[int64]string
|
||||
}
|
||||
|
||||
func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
|
||||
@@ -97,7 +101,7 @@ func newRunner(ctx context.Context, s *pipeline.Store) (*runner, error) {
|
||||
return nil, err
|
||||
}
|
||||
root := filepath.Join(s.Directory(), "artifacts")
|
||||
return &runner{ctx: ctx, store: s, artifactsRoot: root, active: map[int64]activeRun{}, idents: map[int64]runIdentity{}, attentionSent: map[int64]map[string]bool{}, exportSession: stage.ExportSession}, nil
|
||||
return &runner{ctx: ctx, store: s, artifactsRoot: root, active: map[int64]activeRun{}, idents: map[int64]runIdentity{}, attentionSent: map[int64]map[string]bool{}, notifyModes: map[int64]string{}, exportSession: stage.ExportSession}, nil
|
||||
}
|
||||
|
||||
func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.RunDetail, error) {
|
||||
@@ -263,10 +267,11 @@ func (r *runner) start(request protocol.Message, retryOf ...int64) (*protocol.Ru
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, pipeline.RunOverrides{Model: request.Model, StageModels: request.StageModels}, runTitle, retryOf...)
|
||||
id, created, err := r.store.CreateRunTitled(r.ctx, d, request.RequestKey, workspace, request.AllowTools, request.WritePaths, request.Input, pipeline.RunOverrides{Model: request.Model, StageModels: request.StageModels, NotifyMode: request.NotifyMode}, runTitle, retryOf...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.setNotifyMode(id, request.NotifyMode)
|
||||
// The run row now exists: read it once for its resolved identity (pipeline
|
||||
// id/name, the store-derived title, the pinned version), so the queued frame
|
||||
// and every later frame carry what a client needs to render a brand-new run
|
||||
@@ -658,7 +663,11 @@ func (r *runner) retry(request protocol.Message) (*protocol.RunDetail, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return r.start(protocol.Message{PipelineID: original.PipelineID, Version: version, RequestKey: request.RequestKey, RetryMode: mode, RetrySource: original.ID, RetryStage: request.RetryStage, RetryVisit: request.RetryVisit, RetryInput: request.RetryInput, Workspace: original.Workspace, Input: original.Input, AllowTools: original.AllowTools, WritePaths: original.WritePaths, Model: original.Model, StageModels: original.StageModels}, original.ID)
|
||||
notifyMode := request.NotifyMode
|
||||
if notifyMode == "" {
|
||||
notifyMode, _ = r.store.RunNotifyMode(r.ctx, original.ID)
|
||||
}
|
||||
return r.start(protocol.Message{PipelineID: original.PipelineID, Version: version, RequestKey: request.RequestKey, RetryMode: mode, RetrySource: original.ID, RetryStage: request.RetryStage, RetryVisit: request.RetryVisit, RetryInput: request.RetryInput, Workspace: original.Workspace, Input: original.Input, AllowTools: original.AllowTools, WritePaths: original.WritePaths, Model: original.Model, StageModels: original.StageModels, NotifyMode: notifyMode}, original.ID)
|
||||
}
|
||||
|
||||
func (r *runner) cancel(id int64) error {
|
||||
@@ -1272,6 +1281,7 @@ func (r *runner) finishRunState(id int64, name, workspace, status, outcome, diag
|
||||
r.notifyRun(id, name, status, sequence, currentStage, diagnostic)
|
||||
// The run is terminal: nothing more can notify for it.
|
||||
r.forgetAttention(id)
|
||||
r.forgetNotifyMode(id)
|
||||
}
|
||||
|
||||
// completedSteps counts the completed steps of a run detail; resume uses it to
|
||||
|
||||
@@ -17,6 +17,7 @@ type RunOptions struct {
|
||||
// through to the run request without adding a TUI picker (that is a follow-up).
|
||||
Model string
|
||||
StageModels map[string]string
|
||||
NotifyMode string
|
||||
}
|
||||
|
||||
func NewRun(ctx context.Context, url string, options RunOptions) Model {
|
||||
|
||||
@@ -147,7 +147,7 @@ func (m *Model) startSelectedRun() tea.Cmd {
|
||||
m.runCollapsed = nil
|
||||
m.runDetail = nil
|
||||
m.runTop = 0
|
||||
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Title: m.cliOptions.Title, Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace, Model: m.cliOptions.Model, StageModels: m.cliOptions.StageModels}
|
||||
request := protocol.Message{Type: protocol.RunPipeline, PipelineID: m.detail.ID, Version: m.detail.Version, RequestKey: fmt.Sprintf("tui-%d", time.Now().UnixNano()), Title: m.cliOptions.Title, Input: initialRunInput(m.runTask), AllowTools: m.runHasMutationTools(), WritePaths: m.runPaths, Workspace: m.runWorkspace, Model: m.cliOptions.Model, StageModels: m.cliOptions.StageModels, NotifyMode: m.cliOptions.NotifyMode}
|
||||
updated, cmd := m.runRequest(request)
|
||||
*m = updated.(Model)
|
||||
return cmd
|
||||
|
||||
Reference in New Issue
Block a user