Files
pipelines/internal/protocol/message.go
T
alan a6aff47117 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).
2026-10-16 16:47:28 +01:00

152 lines
6.3 KiB
Go

package protocol
import "git.a-wan.net/alan/pipelines/internal/buildinfo"
const (
Ping = "ping"
Pong = "pong"
Error = "error"
Submit = "submit"
Submitted = "submitted"
List = "list_pipelines"
PipelineList = "pipelines"
GetPipeline = "get_pipeline"
Pipeline = "pipeline"
ListTemplates = "list_templates"
Templates = "templates"
Validate = "validate"
Validated = "validated"
)
type Stage struct {
Limits *StageLimits `json:"limits,omitempty"`
Memory map[string]string `json:"memory,omitempty"`
Notify *NotificationPolicy `json:"notify,omitempty"`
Key string `json:"key"`
Type string `json:"type,omitempty"`
Output string `json:"output"`
Prompt string `json:"prompt"`
Configs map[string]string `json:"configs"`
Edges map[string]string `json:"edges"`
FallbackError bool `json:"fallback_error"`
// Additional type-specific Markdown blocks; legacy model fields remain above.
Blocks map[string]string `json:"blocks,omitempty"`
}
// Limits are enforced by the runner and never included in the model prompt.
type StageLimits struct {
MaxVisits int `json:"max_visits"`
On []string `json:"on,omitempty"`
}
type NotificationPolicy struct {
On []string `json:"on"`
Destination string `json:"destination"`
Artifacts []string `json:"artifacts,omitempty"`
}
// Public phone setup only. Never include publishing endpoints or credentials.
type NotificationEndpoint struct {
Destination string `json:"destination"`
ServerURL string `json:"server_url,omitempty"`
Topic string `json:"topic"`
}
type Template struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
Source string `json:"source"`
Scheduled bool `json:"scheduled"`
}
type Graph struct {
Stages []Stage `json:"stages"`
Settings *Settings `json:"settings,omitempty"`
}
type Settings struct {
Prompt string `json:"prompt"`
Schedules []Schedule `json:"schedules"`
}
type Schedule struct {
Days []string `json:"days,omitempty"`
Times []string `json:"times,omitempty"`
Every string `json:"every,omitempty"`
Timezone string `json:"timezone,omitempty"`
}
type VersionSummary struct {
Version int `json:"version"`
Stages int `json:"stages"`
CreatedAt string `json:"created_at"`
}
type PipelineDetail struct {
PipelineSummary
LatestVersion int `json:"latest_version"`
VersionCreatedAt string `json:"version_created_at"`
ContentHash string `json:"content_hash"`
Source string `json:"source"`
Graph Graph `json:"graph"`
Versions []VersionSummary `json:"versions"`
}
type PipelineSummary struct {
ID int64 `json:"id"`
Name string `json:"name"`
Version int `json:"version"`
Stages int `json:"stages"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// Message is the JSON envelope shared by the server and client.
type Message struct {
DefaultHarness string `json:"default_harness,omitempty"`
Build *buildinfo.Info `json:"build,omitempty"`
DefaultModel string `json:"default_model,omitempty"`
Evidence []SessionEvidence `json:"evidence,omitempty"`
Usage *UsageStats `json:"usage,omitempty"`
Status *SystemStatus `json:"status,omitempty"`
Graph *Graph `json:"graph,omitempty"`
ExpectedVersion int `json:"expected_version,omitempty"`
Templates []Template `json:"templates,omitempty"`
CreateOnly bool `json:"create_only,omitempty"`
NotificationEndpoints []NotificationEndpoint `json:"notification_endpoints,omitempty"`
Type string `json:"type"`
ID string `json:"id,omitempty"`
Time string `json:"time,omitempty"`
Error string `json:"error,omitempty"`
Name string `json:"name,omitempty"`
Source string `json:"source,omitempty"`
Title string `json:"title,omitempty"`
Version int `json:"version,omitempty"`
Pipelines []PipelineSummary `json:"pipelines,omitempty"`
PipelineID int64 `json:"pipeline_id,omitempty"`
Detail *PipelineDetail `json:"detail,omitempty"`
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"`
RequestKey string `json:"request_key,omitempty"`
Workspace string `json:"workspace,omitempty"`
// Chat is the brokered OpenCode chat traffic (route B). See chat.go for the
// per-type payload structs and the wire shapes they mirror.
ChatSessions []ChatSession `json:"chat_sessions,omitempty"`
ChatSession *ChatSession `json:"chat_session,omitempty"`
ChatCreate *ChatCreateRequest `json:"chat_create,omitempty"`
ChatQuery *ChatQuery `json:"chat_query,omitempty"`
ChatPrompt *ChatPromptRequest `json:"chat_prompt,omitempty"`
ChatMessages []ChatMessage `json:"chat_messages,omitempty"`
ChatEvent *ChatEventFrame `json:"chat_event,omitempty"`
ChatPermission *ChatPermissionFrame `json:"chat_permission,omitempty"`
ChatReply *ChatReplyRequest `json:"chat_reply,omitempty"`
}