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:
@@ -105,6 +105,46 @@ Use this block for intentional file/command restrictions; prose is not a runtime
|
||||
permission policy. Keep ordinary workflows language-neutral and unrestricted
|
||||
within their run directory unless the user asks for a narrower scope.
|
||||
|
||||
## Human (decision) stages
|
||||
|
||||
A `type=human` stage pauses its run until a person chooses one of its outgoing
|
||||
options. It has no model, agent, tools or configs: it needs a nonempty `prompt`
|
||||
block (the operator instructions) and at least one non-`error` `edges` outcome.
|
||||
Its outcomes are exactly its non-error edges, so a draft can express choices such
|
||||
as `deploy`, `revise` or `abort`; the mandatory error edge is a failure route,
|
||||
not a choice. It validates, renders, exports and imports like every other type.
|
||||
|
||||
````markdown
|
||||
# stage gate
|
||||
|
||||
```output
|
||||
The operator's decision evidence.
|
||||
```
|
||||
|
||||
```prompt
|
||||
Review the screenshots and artifacts above, then choose where the run goes.
|
||||
```
|
||||
|
||||
```edges
|
||||
deploy -> publish
|
||||
revise -> worker
|
||||
abort -> #failure
|
||||
error -> #failure
|
||||
```
|
||||
````
|
||||
|
||||
When a run reaches a human stage its step becomes `waiting`, the run reports it is
|
||||
waiting on a person, and nothing later runs. Decide from the TUI (open the run,
|
||||
press `c`, pick an option, optionally type feedback, Enter) or the CLI:
|
||||
`pipelines decide <run-id> [stage] --option KEY [--feedback TEXT]`. The decision
|
||||
and feedback are recorded as the step's evidence (the feedback stays in the step
|
||||
output, never an error diagnostic) and the run resumes along that
|
||||
edge. The wait is persisted, so it survives a server restart. An unknown option is
|
||||
refused with the valid list; a decision to a stage that is not waiting is refused;
|
||||
a repeated decision for an already-decided visit does not double-apply. Cancel and
|
||||
retry keep working while waiting and after a decision, and a human stage is never
|
||||
killed by a stage timeout or `max_visits` (the shared run budget still applies).
|
||||
|
||||
Malformed final JSON has bounded recovery even with `retries=0`; it never changes
|
||||
verdict/evidence. Recovery tries a deterministic local pass first (append missing
|
||||
closing delimiters, drop one trailing comma, or insert the single comma/colon the
|
||||
@@ -139,7 +179,8 @@ are not approved. Warn explicitly before adding/changing schedules.
|
||||
## Notifications
|
||||
|
||||
Stage hooks use the global phone connection, never store credentials. Optional
|
||||
fenced `notify` block: `on=success,failure`, `artifacts=markdown`.
|
||||
fenced `notify` block: `on=success,failure` (add `waiting` to fire when a human
|
||||
stage parks the run), `artifacts=markdown`.
|
||||
Read this skill's `references/notifications.md` for the minimal terminal-path
|
||||
recipe and optional native publisher format. Prefer hooks for ordinary success/error
|
||||
alerts; a request to notify is not a request for a new delivery stage. Do not scan
|
||||
|
||||
@@ -30,10 +30,10 @@ parallel/distributed task engine or a guarantee that model reports are correct.
|
||||
fails another's concurrent run. An active session left over by a restart with no
|
||||
owning active run is an orphan and still refuses new work until interrupted.
|
||||
Reusing that active run's request key reattaches idempotently.
|
||||
There are no parallel branches or built-in human approval stages. Optional
|
||||
worktrees, full backup/restore, automatic database sync and independent
|
||||
verifier stage types are future ideas, not existing capabilities. Do not
|
||||
invent them in definitions.
|
||||
`type=human` decision stages exist and pause the run (see `references/format.md`);
|
||||
there are no parallel branches. Optional worktrees, full backup/restore,
|
||||
automatic database sync and independent verifier stage types are future ideas,
|
||||
not existing capabilities. Do not invent them in definitions.
|
||||
- Services are native or Docker-based. With an existing Docker installation do not
|
||||
start a competing native server. Server APIs are unauthenticated: trusted networks
|
||||
only; never recommend public exposure. Tool scope is not a universal OS sandbox.
|
||||
@@ -86,6 +86,18 @@ Use the authoritative `CLI_PREFIX` from the prompt:
|
||||
bound is a valid, credential-redacted preview envelope (with preserved stage
|
||||
limits, failure/format diagnostics and the retained session pointer), not the
|
||||
complete tool history.
|
||||
- `CLI_PREFIX decide RUN_ID [STAGE] --option KEY [--feedback TEXT] [--json]`: answer
|
||||
a run that is `waiting` on a `type=human` stage. The status and the stage's
|
||||
instructions/options are visible in `runs` and `inspect --json` (and the TUI
|
||||
picker); the stage is inferred from the run's current stage unless named. The
|
||||
choice and feedback are recorded as the step's evidence (its output and derived
|
||||
verdict; the feedback is never an error diagnostic) and the run resumes along
|
||||
`edges[KEY]`. An unknown option is
|
||||
refused with the valid list; a stage that is not waiting is refused; a repeated
|
||||
decision for an already-decided visit does not double-apply. The wait is persisted,
|
||||
so `decide` still works after a server restart. `cancel` and `retry` keep working
|
||||
while waiting and after a decision; a human stage is never killed by a stage
|
||||
timeout or `max_visits` (the shared 30-step run budget still applies).
|
||||
- `CLI_PREFIX run ... --json --wait --wait-timeout DURATION`: `--wait` polls until
|
||||
terminal and `--wait-timeout` bounds only the client wait after admission,
|
||||
independent of per-request `--timeout`. A reached wait limit leaves the admitted run
|
||||
|
||||
Reference in New Issue
Block a user