Documentation
¶
Overview ¶
Package interview implements the pure `orch init` question engine (PRD §18): given the environment Detect found and the answers collected so far, Next derives the next question.Document to show — a batch of independent questions, the pre-approval summary, the terminal hand-off document, or an abort notice. The engine holds no session state of its own: every call is a pure function of its three inputs, so an adapter's stateless step loop (below) is the only protocol this package needs to support, and a revision is simply the adapter editing or deleting an answer and resubmitting — Next re-derives the sequence and re-asks whatever that invalidates.
Step-loop protocol ¶
This is committed now so PR B's CLI wiring has a fixed contract to implement against; nothing in this package is reachable from `orch init` yet (internal/cli's stub and TestNotImplementedCommandsFailClosed are untouched by this PR).
- Bare `orch init` (human invocation, PRD §22): prints a detection report plus guidance that an adapter drives the interactive interview, and the plumbing invocation to run. It never reads stdin (the `orch run status` precedent: a command a human might run directly must never block on a console that never reaches EOF) and exits 0.
- `orch init --step` (adapter plumbing): reads one question.AnswerSet JSON document from stdin and writes one question.Document (json.MarshalIndent) to stdout. The very first call sends `{"schema_version":1,"answers":{}}`. An invalid answer makes Next return an error; the CLI exits 1 with that error's message (ValidateAnswer's message, when the failure is a bad answer) on stderr, and the adapter re-asks the same question. Malformed usage stays exit 2, matching every other command.
- A flag on `init`, rather than a `run`-style verb, because the `run` verbs hard-depend on config.Load plus the state/lock pair — none of which exist before initialization — while PRD §22 already names `init` as the one logical command adapters wrap end to end (`orch resume`'s own flag-based loop is the closest existing precedent).
Index ¶
- Variables
- func InstructionFile(host string) string
- func Next(facts Facts, answers map[string]string, repoRoot string) (question.Document, error)
- func NextConfigure(facts Facts, answers map[string]string, repoRoot string) (question.Document, error)
- func NextConfigureLocal(answers map[string]string, repoRoot string) (question.Document, error)
- type Deps
- type Facts
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoHostEnabled reports that both host.claude.enabled and // host.codex.enabled are answered "no" — the same "at least one // host" rule config.validate enforces on the committed file, // checked here as soon as both toggles are known so the adapter // can fix it before walking any role questions. ErrNoHostEnabled = errors.New("at least one of Claude Code or Codex CLI must be enabled") // ErrUnknownAnswer reports an answer key that names no question in // the sequence the current facts and prior answers derive — either // a genuine typo, or a question that is not (or no longer) // reachable, such as a Codex role answer submitted while // host.codex.enabled is "no". ErrUnknownAnswer = errors.New("answer does not match a currently applicable question") // ErrApprovalBlocked reports an "approval" answer submitted while // Summary.Blockers is non-empty: approval is withheld until every // blocker is resolved and the interview is re-run. ErrApprovalBlocked = errors.New("cannot approve while blockers remain") // ErrBadAnswer reports a free-text answer that fails its // ingestion-time semantic check at materialization: a model string // containing whitespace, or a concurrency value that is not an // integer >= 1. ErrBadAnswer = errors.New("answer fails its semantic validation") )
Sentinel errors callers test with errors.Is. Specifics wrap these with %w and detail (config/run house style) rather than replace them.
Functions ¶
func InstructionFile ¶
InstructionFile returns host's root instruction file name (instructionFileFor's exported form), or "" for an unrecognized host name — exported for internal/bootstrap's disable-validation (validateConfigure), which needs every host's file status without depending on interview's own host-name set.
func Next ¶
Next derives the next document to show, given facts (Detect's most recent snapshot — re-run on every step, since facts never travel inside answers) and answers (every answer collected so far, keyed by question.Question.ID). repoRoot is consulted only once the question sequence is fully answered, to plan the instruction-file changes and scan for nested conflicts (buildSummary) — every earlier step is a pure function of facts and answers alone.
Next fails closed on any answer that does not belong to the currently derivable sequence (ErrUnknownAnswer — covering both a genuine unknown id and a question that is not, or no longer, reachable, such as a Codex role answer while Codex is disabled), on both hosts being disabled (ErrNoHostEnabled), on any present answer failing question.ValidateAnswer, and on an "approval" answer submitted while the summary carries Blockers (ErrApprovalBlocked).
func NextConfigure ¶
func NextConfigure(facts Facts, answers map[string]string, repoRoot string) (question.Document, error)
NextConfigure derives the next document for the `orch configure` interview (PRD §17/§18 applied to editing an already-committed configuration rather than a fresh bootstrap). Like Next it keeps Facts — git/gh readiness and the Detection audit record the terminal Complete document carries forward — but, like NextConfigureLocal, every question default is seeded from the committed configuration, read via os.ReadFile + config.Parse up front (never config.Load, which would layer in a machine-local override: `orch configure` must never treat a local preference as "already committed"). NextConfigure propagates config.ErrNotInitialized when no committed configuration exists yet.
func NextConfigureLocal ¶
NextConfigureLocal derives the next document for the `orch configure-local` interview (PRD §17). Unlike Next it carries no Facts: every default comes from the committed configuration and the current config.local.toml on disk, never the environment, so both are read up front — before any question is asked, not only once the sequence completes the way Next's own repoRoot use is scoped (documented deviation from the init precedent).
Question IDs equal the exact overlay dotted keys config.PreferenceKeys enumerates (the picker's own pick.* ids aside), so an adapter's answers map is itself a preview of the resulting config.local.toml.
NextConfigureLocal propagates config.ErrNotInitialized when no committed configuration exists yet — configure-local overlays onto it and has nothing to seed from otherwise.
Types ¶
type Deps ¶
type Deps struct {
// RepoRoot is the directory Detect probes git and memhub from. It
// need not carry .orchestrator/ yet — Detect runs pre-init.
RepoRoot string
// LookPath resolves an executable name; a nil LookPath makes every
// host/git/gh/memhub fact false.
LookPath func(string) (string, error)
// Runner executes git and memhub. Required whenever LookPath finds
// git or memhub — Detect never calls a nil Runner.
Runner execx.Runner
}
Deps carries Detect's injectable surface: LookPath and Runner are the same shapes cli.Env and execx.Local already use, so a real caller wires them identically and a test substitutes fakes.
type Facts ¶
type Facts struct {
ClaudeCLI bool
CodexCLI bool
Git bool
GitRoot string
Gh bool
MemhubCLI bool
MemhubHealthy bool
MemhubDetail string
}
Facts is Detect's pure snapshot of the local environment (PRD §18 steps 1-2): which host CLIs are on PATH, whether RepoRoot sits inside a git repository, whether gh is on PATH, and whether memhub is both on PATH and healthy. Facts feeds question defaults and Complete's audit record; it never travels inside an AnswerSet — an adapter cannot spoof detection by editing the answers map, since Next never reads facts back out of it.
func Detect ¶
Detect probes deps for every Facts field. It never returns an error: an unresolvable tool or an unreachable memhub is data (a false/empty Facts field), not a Detect failure — the interview reports what it found and lets the human decide, rather than fail closed on missing tooling before any question has even been asked.
Git is probed with a raw `git rev-parse --show-toplevel` through Runner rather than gitops.Open, which asserts .orchestrator/ sits at the git root and so cannot hold before initialization exists. memhub is probed the same way internal/run's unexported execProber does — `memhub status` with the repo root as an explicit working directory (PRD §20) — duplicated here in miniature rather than exported from internal/run, which stays a Delivery-only package.