jig docs
Source modules and enforced boundaries

The zoomable map shows execution. This table lists what each of the twelve top-level src/ owners holds. Which owners each may import is allowedOwners in .dependency-cruiser.mjs.

ModuleOwns
domainState, outcomes, business failures, metric totals and pure rules
failuresFailure presentation, panic unwrapping and retry of operations that return a Result
portsExternal capability contracts and their failures
configConfiguration and environment schemas and defaults, run settings, provider policy, presets and scratch naming
observersEvents, metric records, logging and tracing observers
adaptersGit, GitHub, persistence, configuration and preset files, sandbox, terminal and telemetry I/O
flowGeneric flow contracts, engine and step retry policy
promptsAgent request construction
stepsIndividual workflow operations
appPublic operations in src/app/api.ts, repository preparation, the order a run's scope is acquired and released in, sandbox image policy, run lifecycle, concrete workflow assembly, GitHub issue implementation, and the documents and summary line a run leaves for a person
cliCommands, including github implement, input parsing and output
compositionThe executable: captures the process context, builds the run and sandbox runtimes with explicit factories, attaches the observers, binds the public operations and composes the CLI with its concrete dependencies, parses arguments when invoked and shuts down

src/app/run-flow.ts imports steps and flow contracts; steps import flow contracts. The engine calls supplied steps without importing their implementations. src/config/agent-policy.ts owns provider identity and shared model defaults; src/config/scratch-directory.ts owns the .jig convention. src/config/load-config.ts owns the configuration schema, its validation and its defaults, including the step retry count (2) and first retry delay (5000 ms) that runSettingsFrom resolves into RunSettings; neither is an operator setting. src/domain/settings.ts keeps RunSettings, the rules that compare a slice with the resolved settings, and the stopping caps such as HOOK_FAILURE_CAP. src/config/presets.ts owns preset names, first-winner selection, shadowing, the preset schema and whole-role merging over the PresetSource contract in src/config/preset-source.ts, whose candidates come in precedence order and are read only on demand; src/config/config-source.ts is the settings boundary: loadConfig and updateConfig decide required absence, schema validation, defaults and update merging over a source that only moves raw JSON. src/adapters/filesystem/config-source.ts resolves the settings file, reads and parses it and writes it atomically; jig init also takes its concrete path to write the starter file. src/adapters/filesystem/preset-source.ts orders the repository, home, XDG and starter preset directories, maps names to files, checks presence with lstat and reads preset JSON. Adapters own provider construction, credentials, authentication and scratch filesystem operations. Config reads no file, environment variable or home directory: the process edge captures process.env, the working directory and the fallback home directory, and prepareRepository in src/app/repository-preparation.ts hands them to parseEnvironment after checking the repository root and before reading saved credentials and config. jig status and jig presets call readRunStatus and listPresets from src/app/api.ts, bound by composition to the captured context and lazily built sources; they build no runtime. jig run calls startOrResumeRun from the same entry after the CLI has read the request through supplied input capabilities; the operation prepares, selects the preset and then asks composition's openRuntime for the run's capabilities, which runRuntimeFactory in src/composition/run-runtime.ts builds with explicit factories; opening it opens no sandbox, image or run log. When the run asks for its scope, acquireRunScope in src/app/run-scope.ts opens the run's reporting, its sandbox and its workspace from the parts composition supplies and releases what it holds on a panic. runJig owns the lock, store selection, start or resume and the release order through the wrappers in src/app/lifecycle.ts. jig init and jig build call initRepository and buildSandboxImage the same way: each prepares, then asks composition's openSandboxRuntime for its runtime; init decides when to ask the terminal for agents, credentials and save consent, and runs agents only in throwaway sandboxes it closes. sandboxRuntimeFactory in src/composition/sandbox-runtime.ts builds each sandbox over the config and environment it is asked for, sharing one console log. ensureSandboxImage in src/app/sandbox-image.ts decides what to rebuild over the SandboxImageRecipe and SandboxImages ports; the Dockerfile, host user, agent packages, image names and labels belong to src/adapters/sandbox-image/. jig github implement calls implementGithubIssue the same way: it refuses the GitHub token and repository settings before anything is prepared or built, then runs through the same preparation, runtime and release as jig run and hands runJig the accepted request; every Git and GitHub operation it uses arrives as a capability. No command handler receives a runtime factory. src/composition/main.ts owns the executable: it composes the CLI, binds the run, status, preset-listing, init, image-build and issue operations with their concrete dependencies, built lazily, and starts it only when it is the invoked script. Every operation releases what it built before its command resolves, and only then is the output flushed and the process ended. jig uses no dependency-injection container; the sandbox container is Docker's.

npm run lint:dependencies, included in default npm run validate, scans every production source file, including disconnected files. Each must have exactly one of these owners. Specs under src/ are scanned in a separate pass against the public-entry rule only. Native dependency-cruiser folder analysis enforces aggregate acyclicity, including erased type imports and nested paths. A rule over runtime imports only rejects runtime file cycles; intra-module type cycles and mixed cycles broken by erasure pass.

The checker reports the path of each cycle. Select it with npm run validate -- lint:dependencies, or exclude it with npm run validate -- --skip lint:dependencies. See source ownership.