interview

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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":2,"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

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoHostEnabled reports that every offered host toggle is answered
	// "no" — the same "at least one host" rule config.validate enforces on
	// the committed file, checked as soon as all toggles are known so the adapter
	// can fix it before walking any role questions.
	ErrNoHostEnabled = errors.New("at least one of Claude Code, Codex CLI, or OpenCode V2 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 shortening a known model id, or a
	// concurrency value that is not an integer >= 1.
	ErrBadAnswer = errors.New("answer fails its semantic validation")
	// ErrOpenCodeCatalogUnavailable reports an attempt to edit OpenCode role
	// selections without a usable project-scoped model catalog. Unrelated
	// configuration areas remain editable because they never need the catalog.
	ErrOpenCodeCatalogUnavailable = errors.New("OpenCode model catalog is unavailable")
)

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

func InstructionFile(host string) string

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

func Next(facts Facts, answers map[string]string, repoRoot string) (question.Document, error)

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

func NextConfigureLocal(answers map[string]string, repoRoot string) (question.Document, error)

NextConfigureLocal derives the next document without detected host facts. It remains the compatibility entry point for non-OpenCode tests and callers; OpenCode role edits fail with the same actionable catalog error as a real detection failure. The CLI never uses this shortcut: every step and apply reruns initDetect, then calls NextConfigureLocalWithFacts.

Question IDs equal the exact current writer keys config.EditablePreferenceKeys 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.

func NextConfigureLocalWithFacts added in v0.9.0

func NextConfigureLocalWithFacts(facts Facts, answers map[string]string, repoRoot string) (question.Document, error)

NextConfigureLocalWithFacts derives the configure-local document using the live OpenCode catalog while keeping all ordinary defaults sourced from the committed configuration and config.local.toml.

func SiblingInstructionFile added in v0.6.2

func SiblingInstructionFile(host string) string

SiblingInstructionFile returns the root instruction file name of the host that is not host — the file seeding copies conventions from (seed.go). Exported for the same reason InstructionFile is: `orch doctor`'s block-only advisory names that file as the one `orch configure` can seed from, and the claude/codex pairing itself stays owned here (siblingHost) rather than being restated per caller.

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, memhub, and the OpenCode catalog query. It is
	// required whenever LookPath finds one of those commands.
	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
	OpenCodeCLI bool
	// OpenCodeCatalog and OpenCodeCatalogError distinguish a successful
	// (possibly empty) catalog read from a failed one without making
	// Detect return an error or dropping the failure.
	OpenCodeCatalog      opencode.Catalog
	OpenCodeCatalogError string
	OpenCodeWarning      string

	Git     bool
	GitRoot string

	Gh bool

	MemhubCLI     bool
	MemhubHealthy bool
	MemhubDetail  string

	Instructions map[string]InstructionFileState
}

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, whether memhub is both on PATH and healthy, and how each host's root instruction file already stands (Instructions, keyed by host name). 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

func Detect(ctx context.Context, deps Deps) Facts

Detect probes deps for every Facts field. It never returns an error: an unresolvable tool, unreachable memhub, or unreadable OpenCode catalog 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 through internal/memhub's Client, the shared PRD §20 client that runs `memhub status` with the repo root as an explicit working directory. The root instruction files are read directly (classifyInstructionFile), the one probe that touches the repository's own content rather than its tooling.

func DetectBound added in v0.16.0

func DetectBound(ctx context.Context, deps Deps) (Facts, error)

DetectBound uses the same probes as Detect, but never follows a different detected Git root. MCP's launch binding must also cover the catalog and instruction reads inside detection, not just the later interview call. Missing Git remains a fact; a reported root with an unverifiable or different directory identity is an error before any subsequent probes or file reads. Ordinary Detect callers (including first-time init) retain root discovery.

type InstructionFileState added in v0.6.1

type InstructionFileState struct {
	Exists      bool
	Conventions bool
	BlockOnly   bool
}

InstructionFileState is Detect's classification of one host's root instruction file (InstructionFile names it): whether the file exists at all, whether it carries any content outside the Orch managed block, and whether it is nothing but that block. It is deliberately part of Facts rather than something the summary step reads for itself, so the seed question (seed.go) can be derived while buildSequence stays a pure function of facts and answers alone.

BlockOnly is strictly narrower than "Exists && !Conventions", and the difference is load-bearing: the seed question's repair case proposes replacing this file's bytes, so it keys on BlockOnly alone. Every classification this build cannot fully vouch for — an unreadable file, a structurally broken marker pair, a drifted or newer-versioned block, and a file carrying no managed block at all (an empty one included) — reports Exists without Conventions and without BlockOnly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL