Add a human decision stage that pauses a run for an operator's choice
A new registered stage type `human` (internal/stage/human.go) has no model,
agent, tools or configs: its required `prompt` block carries the operator
instructions and its non-error edges are the selectable options. It parses,
validates, renders, exports and imports like every other type (no parser
special-case, no config keys).
At runtime the runner parks the run instead of executing: the step and the run
persist `waiting` with self-contained {prompt, options} evidence, and the run
returns without starting later stages, capturing file diffs, scanning artifacts,
holding a goroutine/timer or applying a stage timeout. The wait is durable: a
restart leaves the waiting rows untouched (RecoverRuns excludes them) and a
rebuilt runtime over the same database still accepts the decision.
`pipelines decide <run-id> [stage] --option KEY [--feedback TEXT] [--json]` and
the TUI `c` picker resolve the decision from the pinned graph in one store
transaction, record the choice and feedback as the step's evidence and resume
along edges[KEY]. An unknown option is refused with the valid list, a stage that
is not waiting is refused, and a repeated decision for an already-decided visit
does not double-apply. Cancel and retry keep working while waiting and after a
decision; a human stage is never killed by a stage timeout or max_visits, and a
`notify` policy can fire an `on=waiting` event.
Docs: the authoring skill references (format.md, operations.md), docs/cli.md and
README describe the stage, the command and the TUI picker. Tests cover stage
validation, the parsing round-trip, the store transitions, a websocket wait/decide
integration, cancel/retry, waiting notifications and a persistence-layer rebuild
(second Open + newRunner over one database, no process restart).
This commit is contained in:
@@ -129,6 +129,9 @@ type Message struct {
|
||||
RunID int64 `json:"run_id,omitempty"`
|
||||
RunDetail *RunDetail `json:"run_detail,omitempty"`
|
||||
Runs []RunSummary `json:"runs,omitempty"`
|
||||
Stage string `json:"stage,omitempty"`
|
||||
Option string `json:"option,omitempty"`
|
||||
Feedback string `json:"feedback,omitempty"`
|
||||
Input map[string]any `json:"input,omitempty"`
|
||||
AllowTools bool `json:"allow_tools,omitempty"`
|
||||
WritePaths []string `json:"write_paths,omitempty"`
|
||||
|
||||
@@ -11,11 +11,67 @@ const (
|
||||
Run = "run"
|
||||
CancelRun = "cancel_run"
|
||||
RetryRun = "retry_run"
|
||||
DecideRun = "decide_run"
|
||||
SetRunTitle = "set_run_title"
|
||||
GetRunEvidence = "get_run_evidence"
|
||||
RunEvidence = "run_evidence"
|
||||
)
|
||||
|
||||
// Waiting statuses. A human stage pauses its run without a live goroutine, so
|
||||
// the run and its step persist these statuses and the decision path resumes
|
||||
// them. Store, server, CLI and TUI read the one pair below, never a literal.
|
||||
const (
|
||||
RunStatusWaiting = "waiting"
|
||||
RunStatusRunning = "running"
|
||||
StepStatusWaiting = "waiting"
|
||||
// NotifyWaiting is the notification event a human stage emits when it parks
|
||||
// the run. It is the same value the `on=` policy accepts.
|
||||
NotifyWaiting = "waiting"
|
||||
)
|
||||
|
||||
// Waiting evidence keys. A human stage records its operator instructions and
|
||||
// its ordered selectable options in the step output, so inspect and the TUI are
|
||||
// self-contained without re-reading the pinned graph.
|
||||
const (
|
||||
WaitingPromptKey = "prompt"
|
||||
WaitingOptionsKey = "options"
|
||||
)
|
||||
|
||||
// NewWaitingEvidence builds the self-contained evidence a human stage persists
|
||||
// at wait time: the operator instructions and the ordered options to choose.
|
||||
func NewWaitingEvidence(prompt string, options []string) map[string]any {
|
||||
ordered := make([]any, len(options))
|
||||
for i, option := range options {
|
||||
ordered[i] = option
|
||||
}
|
||||
return map[string]any{WaitingPromptKey: prompt, WaitingOptionsKey: ordered}
|
||||
}
|
||||
|
||||
// WaitingPrompt reads the recorded operator instructions from a waiting step's
|
||||
// output, or "" when none were recorded.
|
||||
func WaitingPrompt(output map[string]any) string {
|
||||
prompt, _ := output[WaitingPromptKey].(string)
|
||||
return prompt
|
||||
}
|
||||
|
||||
// WaitingOptions reads the recorded selectable options from a waiting step's
|
||||
// output, accepting the string and generic forms JSON decoding produces.
|
||||
func WaitingOptions(output map[string]any) []string {
|
||||
switch options := output[WaitingOptionsKey].(type) {
|
||||
case []string:
|
||||
return options
|
||||
case []any:
|
||||
result := make([]string, 0, len(options))
|
||||
for _, option := range options {
|
||||
if text, ok := option.(string); ok {
|
||||
result = append(result, text)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type SessionEvidence struct {
|
||||
Sequence int `json:"sequence"`
|
||||
SessionID string `json:"session_id"`
|
||||
|
||||
@@ -9,7 +9,9 @@ import (
|
||||
// VerdictReasonKeys is the single ordered definition of the output keys a stage
|
||||
// may use to state why it chose its outcome. The first key carrying usable text
|
||||
// wins. Store, server and TUI all read this one list, so the order never drifts.
|
||||
var VerdictReasonKeys = []string{"verdict", "reason", "decision", "summary", "implementation_summary"}
|
||||
// "feedback" is last so it only states the reason when no model-authored key
|
||||
// does: an operator's decision feedback is exactly the human stage's reason.
|
||||
var VerdictReasonKeys = []string{"verdict", "reason", "decision", "summary", "implementation_summary", "feedback"}
|
||||
|
||||
// VerdictReasonCap bounds a verdict reason to this many runes, whether it was
|
||||
// generated by the model or derived at read time. It is the same cap the
|
||||
|
||||
@@ -70,6 +70,8 @@ func TestDeriveVerdictReasonKeyOrder(t *testing.T) {
|
||||
{"implementation_summary alone", map[string]any{"implementation_summary": "i"}, "i"},
|
||||
{"non-string is encoded", map[string]any{"summary": 42}, "42"},
|
||||
{"empty values skipped to a later key", map[string]any{"reason": " ", "summary": "s"}, "s"},
|
||||
{"feedback states the reason when nothing else does", map[string]any{"option": "go", "feedback": "looks good"}, "looks good"},
|
||||
{"summary still wins over feedback", map[string]any{"summary": "s", "feedback": "f"}, "s"},
|
||||
{"none yields nothing", map[string]any{"other": "x", "screenshots": []any{"a.png"}}, ""},
|
||||
{"nil output yields nothing", nil, ""},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user