Documentation
¶
Overview ¶
Package scaffold creates a new orch project on disk — what `orch init` does once the flags or the wizard have decided what to build.
Ported from `orch_init` in `orchestrator/init_cmd.py`.
The package is named for the work rather than for the command, like `budget`, `prompt` and `router`. `internal/init` was the name in the brief; a Go package called `init` compiles but cannot be referenced without an import alias at every call site, which is a papercut charged to everyone who ever imports it.
What "scaffolded correctly" means ¶
Not "the files exist". Bug 14 was a scaffolder whose output could not run: every file it promised was on disk, and the first command its own banner suggested exited 1, because the router it wrote had no routes for the tasks it wrote. The test that catches that runs the project; the tests that assert on files did not. So Result carries what was produced, and the caller can check the project rather than the file list.
Index ¶
- Constants
- Variables
- func AllowAgyTools(path string, rules []string) ([]string, error)
- func AllowOrchTools(root string) ([]string, error)
- func AppendRoutes(root string, plan RefreshPlan, by string) error
- func DiscoverySummary(installed func(model.Backend) bool, lists ModelLists, failed []model.Backend, ...) string
- func InstalledTierDefaults(installed func(model.Backend) bool, lists ModelLists) (map[string]string, error)
- func OnlySampleTask(tasks []model.Task) bool
- func PackagedRouter() (router.Router, error)
- func RunLocally(root string, inPlace bool) error
- func SeedInstalledRoutes(root string, installed func(model.Backend) bool, lists ModelLists) ([]string, error)
- type ConflictError
- type ModelLists
- type Options
- type RefreshPlan
- type Result
- type WizardIO
Constants ¶
const FindingsOfferName = "report-findings.offer"
FindingsOfferName is the marker, under .orchestrator/, that has the first `orch run` to finish a task offer report_findings (#376). `orch init` wrote it from #380 until #399 turned report_findings on in a new project; it is still honoured for the projects scaffolded in between.
const SampleTaskID = "F0.T1"
SampleTaskID is the id of the task a blank project starts with.
Variables ¶
var ErrTemplateNotFound = errors.New("unknown template")
ErrTemplateNotFound is re-exported so a caller can tell a bad --template from a filesystem problem without importing templates as well.
Functions ¶
func AllowAgyTools ¶
AllowAgyTools adds the rules that are missing to agy's settings file at path, the same way (#383).
func AllowOrchTools ¶
AllowOrchTools adds the rules of doctor.OrchToolRules that are missing to the project's .claude/settings.json, creating it when there is none, and returns what it added. It only adds: a rule the operator wrote, an allow or a deny, is never removed or reordered, and the file's other keys keep their order. A file that is not a JSON object is an error, not a rewrite.
settings.json rather than settings.local.json: it is the one a worktree checks out, and the engine passes its permissions to every claude dispatch (#361).
func AppendRoutes ¶
func AppendRoutes(root string, plan RefreshPlan, by string) error
AppendRoutes appends plan's additions to root's model_router.yaml under a comment naming the command that added them.
func DiscoverySummary ¶
func DiscoverySummary(installed func(model.Backend) bool, lists ModelLists, failed []model.Backend, r router.Router) string
DiscoverySummary is what init and start say about the discovery (#547): one line, per installed CLI the routes r (the project's router) gives it, how many of the models it lists no route runs, or that its list failed. The models themselves are `orch router refresh`'s to show. Empty when no CLI is installed.
func InstalledTierDefaults ¶
func InstalledTierDefaults(installed func(model.Backend) bool, lists ModelLists) (map[string]string, error)
InstalledTierDefaults picks each tier's default model among the packaged routes whose CLI installed accepts — router.OnPath for a real machine — so a new project never defaults to a CLI that is not there (#376, #377). A tier no installed backend serves is left out. A route whose CLI listed its models without the route's (lists, DiscoverModels) is not a candidate (#397).
func OnlySampleTask ¶
OnlySampleTask reports whether tasks are just the sample task init wrote: a project with nothing planned yet, as far as `orch start` is concerned.
func PackagedRouter ¶
PackagedRouter is the router every scaffold starts from, parsed.
func RunLocally ¶
RunLocally sets vcs.provider: local in root's config.yaml, for a repository with no remote or no gh (#455): each task still works on its own branch, and when it passes it is squash-merged into the base branch here — no push, no pull request. inPlace also turns dispatch.worktree_mode and vcs.auto_pr off, for a repository with no commit yet to branch from: the agents work straight in the checkout, as every project with no remote did before #455 (#377).
func SeedInstalledRoutes ¶
func SeedInstalledRoutes(root string, installed func(model.Backend) bool, lists ModelLists) ([]string, error)
SeedInstalledRoutes appends to root's model_router.yaml the packaged routes whose CLI installed accepts and the file does not have yet, and returns their keys. A blank project's router is empty; a planner choosing models for it then has real routes, with their tiers, to choose from (#377). Routes lists says their CLI no longer runs are left out (#397).
Types ¶
type ConflictError ¶
ConflictError is a destination that already holds a file `orch init` writes.
Checked before ANY write, so a refused scaffold leaves the directory exactly as it found it — a half-scaffolded project is worse than none, because the files that did land make it look finished.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type ModelLists ¶
ModelLists is, per backend, the models its CLI said it runs now (#397). A backend missing from it is unknown — no model list, or the CLI could not give one — and keeps every packaged route.
func DiscoverModels ¶
func DiscoverModels(ctx context.Context, installed func(model.Backend) bool) (lists ModelLists, failed []model.Backend)
DiscoverModels asks each installed CLI that has a model list (opencode, agy, codex; see providers.ModelLister) for it, all at once, each cut off at discoverTimeout. A CLI that fails, hangs or prints nothing readable is left out of lists and named in failed, by router.BackendPreference: init goes on with its packaged routes and says so.
type Options ¶
type Options struct {
// Root is where the project goes. Created if absent.
Root string
// Name fills PROJECT_NAME. Empty means the base name of Root.
Name string
// Template is one of templates.Names(), or empty for a blank project.
Template string
// Force overwrites the files the conflict check guards. It does not
// overwrite `.gitignore`, which is a soft target either way.
Force bool
// SDD adds the openspec/ layout.
SDD bool
// Now stamps GENERATED_AT. Zero means time.Now — a parameter so a test
// can have a fixed expectation.
Now time.Time
// The three answers the wizard collects that are not decided by the
// template. Empty means "leave the config as the template or the
// packaged default wrote it", which is what batch mode wants: a flag
// nobody passed must not overwrite a value the template chose.
StateBackend string
BudgetPreset string
SpecRoot string
// BaseBranch is the branch task worktrees start from: the repository's
// own, when `orch init` runs in one (#376 — `git init` names it master
// on many machines, and a project pointed at main never ran a task).
BaseBranch string
// TierDefaults is the wizard's per-tier model pick, stamped into
// tasks.json's meta block for downstream tools. Keys: premium, standard,
// cheap.
TierDefaults map[string]string
// Models is what each installed CLI said it runs now (DiscoverModels).
// The wizard and batch init pick TierDefaults among the packaged routes
// it keeps; nil keeps every packaged route (#397).
Models ModelLists
// NoSampleTask leaves a blank project without the sample task — for
// `orch start`, which plans the real ones right away.
NoSampleTask bool
// NoReportFindings is the operator saying no (`--no-report-findings`).
// The zero value writes `report_findings.enabled: true` (#399).
NoReportFindings bool
}
Options are the decisions a scaffold needs. The zero value scaffolds a blank project into the current directory under its own name.
func Wizard ¶
Wizard asks the questions and returns the Options they describe.
Three by default (#376): the project id, the template and the confirm gate. Everything else takes the value a new project should have — the current directory, models of the CLIs that are installed — and `advanced` asks about it too: root, state backend, budget preset, spec root, the three tier models, openspec.
`confirmed` is false when the operator declined at the gate — not an error: answering "no" to "shall I write this?" is the gate working. The caller exits 0 and says nothing was written.
type RefreshPlan ¶
type RefreshPlan struct {
// Add are the packaged routes of installed CLIs the file lacks and,
// where the CLI lists its models, that it still runs; Keys sorted.
Add map[string]model.RouteEntry
Keys []string
// Stale are the file's routes whose CLI listed its models without the
// route's cli_model: a dispatch to one fails as version_drift.
Stale []string
// Unrouted are, per CLI, models it lists that no route runs: new models
// orch has no tier for, for the operator to route by hand.
Unrouted map[model.Backend][]string
}
RefreshPlan is what the packaged routes and the CLIs' model lists would change in a project's model_router.yaml (`orch router refresh`, #448).
func PlanRefresh ¶
func PlanRefresh(root string, installed func(model.Backend) bool, lists ModelLists) (RefreshPlan, error)
PlanRefresh reads root's model_router.yaml against the packaged routes and lists (DiscoverModels); it writes nothing.
type Result ¶
type Result struct {
Root string
Name string
// RoutesAdded names the router entries inferred from the template's
// tasks, sorted. Empty for a blank project, which has no tasks.
RoutesAdded []string
// RoutesUninferable names models whose key has no `backend/` prefix, so
// no route could be guessed. A human has to add these.
RoutesUninferable []string
// Warnings are things the operator should see but that did not stop the
// scaffold.
Warnings []string
// SampleTask is the id of the task a blank project starts with, so the
// first `orch run` has something to show; empty when none was written.
SampleTask string
}
Result is what a scaffold produced, for the caller's banner and for tests that want to check the project rather than a list of paths.
type WizardIO ¶
type WizardIO struct {
// contains filtered or unexported fields
}
WizardIO is the wizard's terminal: a line source and a place to print.
An explicit type rather than reading os.Stdin inside, so a test drives the whole flow with a scripted string and reads back exactly what an operator would have seen. Python takes an `input_fn` for the same reason.
func NewWizardIO ¶
NewWizardIO wires the wizard to a reader and a writer.