Repository navigation
Cli Command Surface
📖 loopsmith's documentation lives at bitphill.github.io/loopsmith → This wiki mirrors it so existing links keep working.
← Wiki home · Rendered viewer with search
The crate that publishes as loopsmith and builds the loopsmith binary. Nothing here runs a loop, evaluates a gate, or decides a verdict — those live in loopsmith-run, loopsmith-gate, and loopsmith-core. This crate owns exactly three things:
-
The argument grammar — what you can type and what it means (
src/cli/). -
The command bodies — one module per action, each of which loads a config, calls into a library crate, and prints (
src/cmd/). -
Loop scaffolding — materialising a new loop directory, launchers and all (
src/scaffold.rs,src/guided.rs).
A useful mental model: this crate is a translator. Argv comes in, a Command enum comes out, a library crate does the work, and an ExitCode goes back to the shell. Every design decision below follows from keeping those four stages separate.
| Path | Job |
|---|---|
src/main.rs |
Entry point only — 38 lines, no command logic |
src/cli/mod.rs |
The clap grammar: Cli, Command, and the four action enums |
src/cli/alias.rs |
The 0.3 → 1.0 spelling table, applied before clap |
src/cmd/mod.rs |
dispatch, the two noun routers, and four shared helpers |
src/cmd/*.rs |
One module per leaf action |
src/scaffold.rs |
loopsmith loop new's filesystem work, shared with the wizard |
src/guided.rs |
The terminal wizard front end |
templates/ |
Files compiled in with include_str!
|
main is deliberately the whole control flow, and it is short enough to read as the spec:
flowchart LR
A["std::env::args()"] --> B["cli::alias::rewrite<br/>0.3 → 1.0 spellings"]
B --> C["Cli::parse_from<br/>clap"]
C --> D["Cli::resolve<br/>--web / --guided collapse"]
D --> E["cmd::dispatch<br/>match on Command"]
E --> F["command module<br/>Result<ExitCode, String>"]
F --> G["ExitCode, or<br/>eprintln! + FAILURE"]
Each boundary exists to keep the next stage simple:
-
rewriteruns before clap so the grammar incli/mod.rsholds only 1.0 spellings. The compatibility layer is one table in one file, deletable whole at 2.0 rather than unpicked from twenty-eight hidden subcommands. -
resolveruns after clap sodispatchis a pure match overCommandwith no knowledge that--webandwebare the same thing. -
Command bodies return
Result<ExitCode, String>and never callprocess::exit. That makes each one callable from a test — and fromguided::offer_run, which invokescmd::run::executedirectly after scaffolding. -
One error path.
mainprintserror: {e}and returnsFAILURE.resolve's errors are the sameStringshape as a command's, so both take that path.
1.0 groups actions under four nouns, with four machine-level commands left flat: eight top-level subcommands, twenty-eight leaf actions.
| Noun | Actions | Concern |
|---|---|---|
loop |
new, guided, validate, plan, convert, migrate, permissions
|
The config file itself |
run |
start, resume, status, ledger, gate, watch, schedule, proposals, prune
|
One run of a loop, and what it left behind |
memory |
list, promote, forget
|
What the loop remembers across runs |
skills |
list, search, acquire, install, scores
|
Sub-agent discovery and scoring |
| (flat) |
doctor, providers, web, mcp
|
One thing about this machine, not about a loop |
Cli also carries four global flags — --web, --guided, and --guided's two modifiers --novice / --expert plus --ask. resolve turns them into Command::Web or Command::Loop { action: LoopAction::Guided { .. } }, and refuses the contradictions explicitly rather than guessing:
-
--web+--guided→ "two front ends for the same thing — pick one" -
--web+ a subcommand → "--webstarts the browser UI and takes no subcommand" - neither, and no subcommand → a message naming
loopsmith loop guidedandloopsmith web
--novice, --expert, and --ask are declared with requires = "guided", so clap rejects them on their own; the guided subcommand declares the same three flags itself, so the short spelling is not a lesser one.
Every 0.3 verb was flat (loopsmith validate, loopsmith watch). Those spellings are in shell histories, Makefiles, crontab lines written by schedule --install, and the run.sh / run.cmd launchers in every loop directory the binary has ever scaffolded. So rewrite fixes up argv and prints one note via Moved::notice.
Two tables do the work:
-
MOVED— fifteen(verb, noun)pairs. A match inserts the noun at position 1. -
RUN_VERBS— the verbs underrun, becauserunis the one collision: a noun in 1.0, a verb in 0.3.
The run disambiguation is the subtle part. loopsmith run <config> must keep running the loop:
if first == "run" {
let verb_next = args.get(2).is_some_and(|n| RUN_VERBS.contains(&n.as_str()));
let has_config = args[2..].iter().any(|a| !a.starts_with('-'));
if verb_next || !has_config { return (args, None); } // the 1.0 noun
args.insert(2, "start".into()); // the 0.3 verb
}Reading the token straight after run rather than the first non-flag token anywhere is what keeps --run-id start loop.yaml from being misread as the start verb. Checking for any later non-flag token is what keeps 0.3's flags-before-positional form (run --dry-run loop.yaml) working. Only the first argument is ever inspected, so a config file literally named validate is safe.
Four tests in this file are load-bearing well beyond it, and are the reason a command rename is a single-commit change:
-
every_moved_verb_lands_on_a_noun_that_existsandevery_run_verb_is_a_real_onehold the tables against the clap grammar viaCommandFactory. A verb missing fromRUN_VERBSwould be read as a config path. -
the_browser_never_asks_for_a_spelling_that_moved(feature-gated onweb) walksloopsmith_web::exec::all_actions()and asserts both that clap accepts each argv and thatrewritehas nothing to say about it. A 0.3 spelling in the web UI would still work — by coming through this table — and would land a deprecation notice in the console of someone who pressed a button and typed nothing. -
no_document_tells_anyone_to_type_a_spelling_that_movedwalks every.md/.sh/.cmd/.rb/.htmlin the repository, scrapes invocations out of prose withcommands_in, and runs each throughrewrite.CHANGELOG.mdand the migration wiki page are exempted by name. It assertsseen > 100so a scanner that silently stops reading fails too.
cmd/mod.rs holds four helpers every command reaches for, and they encode invariants worth knowing:
-
config_dir(config)— the config's directory, normalised to.whenPath::parent()yieldsSome("")for a bareloop.yaml. An empty path is not a usable working directory; spawning into one fails with ENOENT. -
config_file_name(config)— the bare file name, for scripts generated inside the loop directory thatcdthere first. -
open_store(config)— opens the sled store at<config_dir>/state. Every command that reads a run's history goes through this. -
report_outcome(&RunOutcome)— the one place a finished run is printed: run id, iterations, state,stop.describe(), spend (flagging estimates when no provider reported usage), alerts, baseline, proposal count, per-target verdicts, log path, export path. On failure it prints therun ledgercommand to type next. Shared byrun,resume, andwatchso all three read identically.
dispatch routes Command::Loop and Command::Run to loop_noun and run_noun; Memory and Skills are matched inline. Only validate is a private mod; every other command module is pub so the wizard and tests can call it.
ExitCode is part of the interface, because a scheduler or CI step should not have to parse output:
| Command | Non-zero when |
|---|---|
run start / run resume
|
!out.stop.is_success() — via run::exit_code
|
run gate |
the target is not satisfied |
loop validate |
report.has_errors(), or --strict and any warning |
loop migrate --check |
the file still uses 0.3 keys |
skills install |
any declared default_skills entry failed |
doctor |
never — advisory by design. Reporting a constraint is not the machine being unusable, and a non-zero exit would fail a CI step that was working fine |
-
doctorprobes rather than infers:Platform::detect()for OS, userland, bash version,/bin/sh, and installed scheduler;whichforgit/sh/sed/awk/curl;loopsmith_run::container::probe()for a container runtime.sed's in-place flags are printed with the empty argument rendered as'', because that argument is the GNU/BSD difference. Given a config,config_notesadditionally resolves everyDetector::Scriptcommand — relative paths against the loop directory, bare names againstPATH— and reports missing or non-executable detectors before the first gate evaluation discovers them. -
watchis the resident loop. It refuses up front when every trigger isTrigger::Manual(it would sleep forever), primes aschedule::Watcherthat ignores the<name>-successexport directory so afile_changetrigger cannot fire on the loop's own output, and then polls. Several triggers firing in one poll start one run, at the shallowest depth any of them allows;Decision::DuplicateandDecision::DepthCappedare printed rather than silently dropped. A failed run logs and continues — that is the difference between a scheduler and a one-shot. -
schedulepicks a scheduler by what is installed, not bycfg!(target_os):launchctl→ plist,schtasks→ a printed command, anything else → a crontab line. Only launchd gets a real--install, because LaunchAgents is one file per job; for the other two,nothing_to_installexplains why rather than accepting the flag as a no-op. Logs go tologs/, neverstate/— the watcher ignores everything understate/, which would have hidden the OS's own record of a failed start. -
migratere-parses its own output and refuses to write a file that does not load: a migration producing an unloadable config has taken a working config away from someone. YAML is rewritten as aserde_yaml::Valuedocument so unknown keys survive; Markdown round-trips through the model. -
proposalsmarks stale entries but never deletes them. A proposal records what the loop wanted at a moment; the moment went stale, not the record. -
mcpservesloopsmith_mcp::Serverover stdin/stdout — the same server a scaffolded loop's.mcp.jsonpoints at.
loop new, loop guided (--guided), and web (--web) all produce the same LoopConfig and all end in scaffold::scaffold. They differ only in how the answers are collected:
-
newnever blocks on a prompt — a command that waits for a keypress cannot run from a Makefile or from the agent setting the loop up. Config can be handed over whole via--config-fileor--config-stdin;read_providedrejects both together and an empty stdin. For a file, the extension decides the grammar (loopsmith_core::is_markdown), because guessing from content would let a stray#reinterpret someone's YAML. -
guided(src/guided.rs) has two paths, and the choice is remembered inloopsmith_wizard::preferences: novice walks every question vialoopsmith_wizard::interview(the same question set the browser renders), expert hands a filled-in config to$EDITORand validates what comes back, preserving the author's own formatting and comments. A flag overrides for one run;--askforgets the preference. With--edit, the result is written back over the same file (write_back, which asks before overwriting); otherwisecreate_loopscaffolds a directory named after asanitized loop name and thenoffer_runoptionally callscmd::run::execute, defaulting the first pass to a dry run. -
webis behind the default-onwebfeature. When the feature is off,dispatchstill matchesCommand::Weband returns an error naming the flag that brings it back, rather than pretending the command does not exist.
scaffold(&NewLoopArgs) -> io::Result<Scaffold> creates the directory tree (state, logs, out, proposals, generated-skills, .claude/skills), writes the config, the harness, and both launcher flavours, then optionally initialises git.
Guardrails, in order:
-
guard_pathrefuses an empty path, a filesystem root, the user's home directory, and — the load-bearing one — anywhere inside the loopsmith installation.install_rootfinds that installation by walking up fromcurrent_exelooking forconfig/loop.schema.jsonandruntime/Cargo.tomltogether. A loop edits files, installs sub-agents, and writes state; pointed at its own runtime, it could modify the thing that runs it. The refusal suggests--path ~/loops/<name>. - A non-empty target directory is refused without
--force. - A supplied config is parsed before anything is written. A loop directory holding an unparseable config is worse than no directory.
Templates are compiled in. MCP_TEMPLATE, PERMISSIONS_TEMPLATE, COMPAT_TEMPLATE, MARKETPLACES, README_TEMPLATE, and the four launcher templates are include_str!ed from templates/. That makes a new loop self-contained and makes it impossible for loop new to touch the checkout it was launched from. They live in the crate rather than the repository's config/ for a packaging reason, not a stylistic one: an include_str! reaching above the crate root compiles locally and fails cargo package --verify. Cargo.toml's include list is anchored with leading slashes for the same class of reason — unanchored README.md would also match tests/README.md.
fill(template, values) substitutes {{key}} in one pass over the template, never over the values, so a purpose containing {{name}} comes out verbatim. An unknown key is left as {{key}}, and every_template_placeholder_is_filled turns that into a test failure.
Launchers. Both .sh and .cmd are written on every host, unconditionally — a loop directory outlives the machine that made it, and cmd.exe cannot run a shebang script while no POSIX shell will run a .cmd. The shell scripts use #!/bin/sh and POSIX-only syntax because macOS still ships bash 3.2. The batch files are converted by crlf on the way out and have exactly one exit /b on the last line: an implicit endlocal restores the errorlevel setlocal saved, and endlocal & exit /b does not work inside a nested if (…) block, so every path sets CODE and falls through. binary_path pins an absolute path (cron and launchd inherit no PATH) but deliberately does not canonicalize an already-absolute one, because resolving Homebrew's symlink would pin a version number that dies on the next upgrade.
init_git is what makes isolated: true isolate anything. It runs init, add -A, and a commit — the commit is not optional, since git worktree add resolves a start point and a repository with no HEAD has none. Identity is passed inline with -c rather than written to the repo config, so a machine with no user.email still works and nobody's git identity is edited to scaffold a loop. Failure is reported, never fatal: Scaffold::git is Some(Ok(())), Some(Err(why)), or None, and cmd::new prints the warning because a silent failure here surfaces much later as two builders overwriting each other.
starter_config builds the shipped starter: a two-node build → judge graph, Environment::Dev, every risky feature off, enforce_judge_independence: true, and prerequisites whose done flags are all false. It is asserted not to validate as shipped — the_starter_config_validates_once_pre_execution_is_marked_done — because a loop automating a process nobody has performed by hand produces fast, confident garbage.
Every dependency is a one-way call into a library crate; nothing calls back into this one.
| Crate | Used for |
|---|---|
loopsmith-core |
load, load_validated, validate, parse_str/parse_md, render_md, is_markdown, permissions::*, config::legacy::migrate, and the whole config model |
loopsmith-run |
execute, RunOptions/RunOutcome/RunState, collect_evidence, schedule::*, worktree::*, container::probe
|
loopsmith-gate |
evaluate for the one-shot run gate
|
loopsmith-graph |
plan, unisolated_parallel_writers for loop plan
|
loopsmith-memory |
open, Store, score_skills, Checkpoint
|
loopsmith-provider |
availability, starter_providers
|
loopsmith-skills |
list_installed, acquire, install_default, search_marketplace
|
loopsmith-mcp |
Server::serve |
loopsmith-wizard |
interview, Io, Grammar, Outcome, preferences
|
loopsmith-util |
which, is_executable, now_ms, platform::*, testing::*
|
loopsmith-web |
Optional; serve, and exec::argv_for in tests |
- Add the variant to the right action enum in
cli/mod.rswith its doc comment — clap uses it as the help text, so write it for the reader who types--help. - Add a module under
src/cmd/exposingpub fn execute(...) -> Result<ExitCode, String>. Load the config withloopsmith_core::load(orload_validatedif it will run something), useopen_storewhen you need run history, print, return. Do not callprocess::exit. - Wire it into
loop_noun/run_noun/dispatch. - If you add it under
run, add its name toRUN_VERBS— otherwiseloopsmith run <yourverb>is read as a config path.every_run_verb_is_a_real_onefails if you forget. - If you rename or move a command, add the old verb to
MOVED, and expectno_document_tells_anyone_to_type_a_spelling_that_movedto tell you which documents need editing on the same commit. - If the web UI can trigger it,
the_browser_never_asks_for_a_spelling_that_movedwill holdloopsmith_web::exec::argv_forto the new spelling.
Generated by gitnexus wiki from bitphill/loopsmith. Do not edit by hand — regenerated on each run.
Documentation site · Code wiki · Repository
- Architecture
- CLI Command Surface
- The command surface
- Concepts
- Distribution & Installers
- Evolution & Perturbation
- Example Loops
- The example loops
- Execution Graph & Concurrency Planning
- Gating & Success Criteria
- Loop Configuration Schema
- Loop Execution Engine
- Markdown/YAML Config Interchange
- MCP Server
- Memory & Episode Store
- Migration 0.3 → 1.0
- Other
- Permissions & Sandboxing
- Platform Utilities
- Project Documentation
- Provider Integration
- Scheduling & Triggers
- Skills System