# Facade

See [how it works](../../docs/how-it-works.md).

May import: `domain`, `features`, `format`, `program`.

Per the [design](../../docs/plans/2026-11-14-agent-supervisor-design.md) ("Architecture"), this layer is the CLI. It converts input to commands and makes no decisions. It does not import Runtime, so it reaches the shell only through Program.

[`cli-arguments.ts`](cli-arguments.ts) reads the owner's words with `parseArguments`: `--config <path>` first, then one command of slices A1 and A2. [`cli-commands.ts`](cli-commands.ts) holds the commands it returns. Words it cannot read are a `UsageError`. The parser passes `--attest` on as given; Program refuses a handoff without it.

- `worktree create`
- `session open --tranche <id> --task <path>`
- `implement [--waive]`
- `review [--waive] --attest`
- `correct --findings <file> [--waive] --attest`
- `reject [--note <text>]`
- `status`
- `step-ended <opId> --grant <grantId>`
- `session close --abandoned|--interrupted|--unconverged [--note <text>]`
- `session close --finished --attest [--note <text>]`
- `ruling add --text <text> [--supersedes <rulingId>]`
- `overrule <findingId> --note <reason>`
- `rounds grant <n> --note <reason>`

`ruling add`, `overrule` and `rounds grant` (v0.2.0) keep their text and note as given, line breaks included; one that is empty or only whitespace is a usage error, and so is a `--supersedes` that is not a ruling id (`R` and a positive integer). Each prints the event it appended as JSON, `RulingAdded`, `FindingOverruled` or `RoundsGranted`, as `reject` prints `HandoffRejected`. The count of `rounds grant` is decimal digits with no sign and no leading zero, at least 1 and within the safe integers; `02`, `+2`, `2.0` and anything else are usage errors. `--attest` goes only with `--finished`, so `session close --unconverged --attest` is a usage error. Program decides everything else.

A correction refused at the session's limit prints `CorrectionsExhausted` with the corrections launched and the limit; `rounds grant` lifts the limit by its count. `session close --unconverged` then ends a session whose review still asks for changes at the limit, instead of `--abandoned`.

The usage text printed with a usage error ends with the owner's rule for a launch that does not return after its client exited. A process the client started still holds its output, and tarlatan never signals, so the owner interrupts tarlatan and then runs `status`, `step-ended` and `session close --interrupted`.

[`cli.ts`](cli.ts) holds `main`. For every command but `status` it builds the production context in Program from the configuration file and tarlatan's environment, calls the one Program function the command names, and prints the result as JSON on stdout or the failure on stderr. The exit status is 0 on success, 1 when the command failed and 2 on a usage error. `step-ended` is built with Program's `stepEndedProduction`, which opens only the log and the lock, and `session close --abandoned | --interrupted | --unconverged` with `exitProduction`, which also opens the ledger. Both run on the state directory's recorded target, so these exits stay reachable when the configuration names another target or a layout that breaks a rule (batch review B04, focused review finding 2). Neither prepares git's private `HOME`, so a contaminated home does not block them (re-review R02). Every other command is built with `production`, which refuses such a configuration and refuses an unusable git `HOME` with `GitHomeRefused`. Every command but `status` creates a missing state directory, and a command that opens the ledger creates a missing ledger directory, each with mode 0700, when its parent exists. A symbolic link to a directory is followed, as the layout check follows it. The command fails with `StoreDirectoryParentMissing` when the parent is missing too, and with `StoreDirectoryRefused` when the resolved path is not a directory. A dangling symbolic link still fails with `LayoutRefused`.

## The status output contract

For `status`, `main` calls Program's `productionStatus`. It opens the state read-only, takes no lock, writes nothing (SQLite's `-shm` coordination file may change, by the owner's ruling on B11) and reports what is broken beside whatever it can read (re-review R03). It prints one JSON object on stdout and exits 0, whatever it found. It exits 1, with the failure on stderr, only when the configuration cannot be read or decoded, the project log or the ledger cannot be read, or the project log is stamped with a format version this release does not read (`StoreVersionNewer` for a newer one: above 2, the log's known version). A ledger stamped that way is a finding instead, because another project's newer release may share it. It exits 2 on a usage error, like every command.

The object is one of two:

- `StateMissing`, when the configured state directory has no project log: `stateDir`, `logPath` and `findings`.
- `ProductionStatusReport`, with seven fields: `findings`, `target`, `inForce`, `gitHome`, `report`, `checkCommands` and `storeVersions`. `storeVersions` holds each store's format version as its header reads, never stamped by status: `{"log": 1, "ledger": 0}`, or `{"log": 1}` when no target is in force or no ledger file is found. 0 means a store v0.1.0 wrote that no command has opened since. The log reads 1 until the first append holding an event v0.1.1 does not decode (today a usable review's `FindingsRecorded`, the `RulingAdded` and `FindingOverruled` of `ruling add` and `overrule`, the `RoundsGranted` of `rounds grant`, or the `SessionClosed` of `session close --unconverged`) raises it to 2; both are read, and neither is a finding.

`findings` lists each problem status found, in this order, and is empty when there is none:

- `ConfiguredLayoutRefused` with `reasons`: the configured layout breaks a rule or a path in it cannot be resolved (batch review B05).
- `TargetBindingUnreadable` with `binding` and `reason`: the state directory's binding cannot be read or decoded (batch review B04).
- `RecordedLayoutRefused` with `binding` and `reasons`: the recorded target's layout, with the state directory, breaks a rule.
- `StoreVersionNewer` with `path`, `found` and `known`: the ledger of the target in force is stamped by a newer release, above the ledger's known version, 1, which `known` gives. Status reads none of its rows, so `report.ledgerFound` is false and holds that rest on ledger rows are absent; `storeVersions.ledger` shows the version found.
- `LedgerVersionInvalid` with `path`, `found` and `reason`: the ledger is stamped below 0, which no tarlatan release writes, and is treated the same way.

`target` compares the binding with the configuration: `TargetUnbound` when no binding is recorded, `TargetBound` when they agree, `TargetMismatch` with each difference, or `TargetUncompared` when the binding is unreadable or a configured path cannot be resolved. A mismatch is shown, never refused.

`inForce` is the target status ran on. `RecordedInForce` and `ConfiguredInForce` hold that target in `binding`. `NoTargetInForce` means status ran on no target and did not guess a replacement. It then leaves the ledger unread, so `report.ledgerFound` is false and the holds come from the log alone, and it runs no git command.

`gitHome` is `GitHomeUsable` or `GitHomeRefused` with every reason (batch review B02). Status judges the home from a reading and never makes it.

`report` is the status report described in Program's README: the session state, each incomplete attempt with its grant, the holds, the armed waivers, the pin checks, the worktree check, report and brief integrity, the coverage statement and the advisory process evidence. It is read from the configured state directory's log whatever the findings are. The worktree check runs git only when a target is in force, `findings` is empty and the home is usable. Otherwise `report.worktree` has `passed` false and a `detail` that ends in "worktree check skipped". Since dogfood-8 `report.keptRefs` lists every ref under `refs/tarlatan/` by session, each with its commit's tree (none for a ref that points at no commit) and an `orphan` mark for a ref no `SnapshotKept` names, and `report.noKeptEndTree` lists every attempt of the open session with no kept end tree, finished, interrupted, attested ended by the owner or still running. The listing runs under the worktree check's conditions; otherwise `report.keptRefs` is `KeptRefsSkipped` with a `reason` that ends in "ref listing skipped", and status still exits 0. In a repository whose ref storage is not files, such as `reftable`, `report.keptRefs` is `KeptRefsIncomplete`: the refs status could list, and a `reason` saying that a dangling symbolic ref may be missing, since git there lists no ref that resolves to no object; status still exits 0 (review 3 F3). When `session close --finished` committed its close and could not delete every kept ref of the session, it prints `KeptRefsRemain` with those refs on stderr and exits 1. It deletes every ref it could list and does not fail on an incomplete listing alone, so on such a backend a dangling symbolic ref of the session may remain.

`checkCommands` lists the check commands the configuration names, in its order, and is empty when it names none.

[`main.ts`](main.ts) is the entry. Run tarlatan as `bun src/facade/main.ts --config <path> <command>`, with one of the commands above. It passes the words after the script's path and tarlatan's environment to `main`, then exits with the status `main` returns: 0, 1 or 2 as above. Following the owner's ruling of 2026-11-19, it is the only module in `src/` that may reference the `process` global, and only as `process.argv`, `process.env` and `process.exit`. It is also the only module in `src/` that may run an Effect, through one awaited `Effect.runPromise`. The process gate (`test/runtime/git-process-gate.test.ts`) and a named lint exception in `eslint.rules.js` enforce those limits. [`process.d.ts`](process.d.ts) declares those three members of the global and no others.

The design's other commands (`approve`, `reconcile`, `waive`, `release`, `release-protected`, `adopt`, `restore` and `run`) are not built.
