Skip to content

Architecture and module boundaries

Architecture and module boundaries

The driver controls the workflow deterministically. Configured agent CLIs supply the judgment. Other guides cover the public CLI, configuration, phase contracts, and saved run artefacts. This page covers the source-level boundaries behind them.

Pipeline orchestration

src/pipeline.mjs is the composition root. It parses and validates a run, loads configuration and saved state, builds the shared run context, and wires up the operations that execute phases. It also holds the implementation-specific agent, gate, review-repair, manifest, and budget operations.

src/runner.mjs owns the phase workflow. Given normalized phase descriptors and injected operations, it handles:

  • phase selection and skipping on resume;
  • interactive confirmation;
  • clean-tree and publishing guards;
  • retries, and verdict and standalone-gate repair rounds;
  • checkpoints, and completion or stall reporting.

Because this control flow doesn’t depend on the concrete operations, you can change the workflow through descriptors without touching CLI setup or persistence.

Deterministic policy

src/policy.mjs holds decisions that must not be left to an agent prompt:

  • whether a configured phase can be skipped interactively;
  • agent-phase postconditions: a clean tree, HEAD advanced or unchanged as required, and a repair rebuttal when one is required;
  • the publication attestation, which ties the current HEAD to a passing gate and an approved review, or to a recorded repeated-blockers override.

The user-facing rules and failure behavior live in the loop guide and Publishing. Treat those as the source of truth when you change a workflow contract.

Commands, terminal, and worktrees

src/command.mjs runs child processes. It captures output, terminates on timeout, tracks active processes, and resolves executables per platform. See Platform support.

src/reporter.mjs handles everything the terminal sees: progress banners, phase and summary formatting, confirmation input, and the final report. It doesn’t decide which phases run. Its banner and log calls go to whichever renderer is active, so other renderers plug in without runner.mjs or pipeline.mjs knowing which one is live:

  • src/tui.mjs is the live dashboard described in the loop guide.
  • src/quiet.mjs is the quiet mode renderer. It drops raw engine, gate, and setup output and prints phase transitions, log lines, and a periodic heartbeat.

pipeline.mjs picks at most one alternate renderer per run (quiet wins over the TUI) and stops it before the final report, which is always plain text.

src/worktree.mjs plans and creates worktrees and validates them on resume. It checks a saved worktree through Git instead of quietly substituting another checkout. With worktrees: false it instead checks out the run branch in the current checkout: it refuses a dirty checkout on a fresh start, and resumes or switches back to the run branch only when that is safe. See Isolation and state and Run state and recovery.

Static contracts

The runtime is ESM JavaScript. tsconfig.json runs TypeScript in strict, no-emit mode, checking JSDoc across the production modules, CLI, and tests. Shared contracts live in src/types.d.ts. Import them in JSDoc with import('./types.js'). This adds no runtime dependency and no output.

Use the shared contracts for values that cross a module boundary: a phase descriptor, adapter, resolved configuration, run state, manifest entry, or review verdict. Keep local shapes local, and don’t grow the shared file ahead of need. Files marked // @ts-nocheck are deliberately outside the checker while they’re typed step by step. Don’t remove the marker unless the file passes the strict check. test/type-contracts.test.mjs checks the contracts with valid examples and expected invalid assignments.

Run npm run typecheck after changing the shared declarations, JSDoc imports, or a checked file. CI runs it before the tests.

These modules support the orchestration layer:

  • src/config.mjs: configuration normalization
  • src/hermetic.mjs: hermetic runtime policy
  • src/adapters.mjs: agent adapters, including each adapter’s named-agent support (agentSupport)
  • src/agents.mjs: named-agent definitions (lookup, frontmatter parsing, inline prompt wrapping) and the setup diagnostics shared by doctor and runs. See Named agents.
  • src/git.mjs: Git operations. classifyRefChanges sorts the refs that changed during an artifact-only phase into blocking changes (the run’s own branch and tags) and ignored changes (every other ref). pipeline.mjs applies it in runAgent, not policy.mjs. See Isolation and state.
  • src/operational-context.mjs: resolves the repository root and runs directory for operator commands. It loads configuration with loadConfig when validation is requested, and otherwise uses a lenient loader that falls back to defaults only when no config file exists.
  • src/operations.mjs exports the operator commands. src/run-read.mjs supplies the lock-aware read model for both API and CLI callers. src/run-control.mjs handles cancellation, src/run-clean.mjs handles retention and cleanup, and src/operational-setup.mjs owns init and doctor. src/run-lock.mjs shares lock reading and liveness with state.mjs. See Operational run commands.
  • src/publish.mjs: the publish use case, the GitHub backend, and backend resolution. src/backends/gitlab.mjs holds the bundled GitLab backend and glab transport. See Publishing.
  • src/evidence.mjs: the evidence phase’s pure and host-side helpers: plan normalization, scenario execution and receipts, summary-manifest validation, and the scoped evidence commit. pipeline.mjs (runEvidence) drives it. See Evidence scenarios.
  • src/prompts.mjs: prompts
  • src/state.mjs: durable state
  • src/review-routing.mjs: reviewRouting normalization and the per-round risk assessment (file count, changed lines, binary changes, sensitive globs) that selects the reviewer tier. See Risk-based review routing.
  • src/verdict.mjs: review verdicts and the unanimous aggregate across a reviewer group
  • src/judge.mjs: repeated-blocker judge transports, request building, and answer validation. runner.mjs decides when to call it. It also classifies recorded judge entries (judgeOutcome) and formats their one-line summary (describeJudgeEntry). The run log, aloop watch, and metrics share these, so their wording and outcome labels match.

src/help-topics.mjs sits outside the orchestration layer. It backs aloop help: it lists commands and guides, assembles each command manual from the ## sections of the guides listed in COMMAND_MANUALS, and rewrites links between guides into aloop help references. It reads docs/ at runtime, so docs/ must ship in the npm package (package.json files). Renaming or removing a heading that a manual maps to changes that manual’s output, and test/help-topics.test.mjs checks that the mapped sections exist. See Agentic loop runner.

Before you change a contract that users can see, read the matching guide: