Operations

terret.app.Main listens on HTTP by default. From this repository, ./histos run app starts it on http://127.0.0.1:8080/mcp.

./histos run app -- restart stops the supervised process, waits until it has exited and the port is free, starts it, and returns when the new server is listening. That command stays in the caller's session, so a session under the launchd job dies with the job before the start.

scripts/terret-restart detaches first, unloads the job, polls until the port is free, starts it, and polls until it is listening. Install it with install -m 755 scripts/terret-restart ~/.local/bin/terret-restart.

TERRET_SUPERVISOR selects launchd, foreground, or none. none is the default and does not call a service manager. launchd reads terret.launchd.labels (TERRET_LAUNCHD_LABELS) and terret.launchd.plistDir. There is no built-in job label. foreground reads terret.foreground.command, one executable path. The server writes pidFile when it starts. Webhook subscriptions and ring heads are stored in subscriptions.json beside that file. sessions.json is stored in terret.state, which defaults to that same directory. The directory is mode 0700 and the file is mode 0600. Keep both the index and grok-history/ in this directory when moving server state. The index links each locally spawned Grok session to its private history. Rows without that link cannot be resumed on local Grok transports. Terret leaves the old ~/.grok/sessions tree untouched.

A restart keeps each subscription that still restores, with the same id and cursor, and the next event is one past the saved head. A subscription that names a session this process does not hold, or that cannot be restored, is skipped and logged, and startup continues. A subscription whose deliveries are failing is left to expire. Restart waits use terret.restart.pace, terret.restart.exit, terret.restart.port, and terret.restart.listen.

Managed worktrees

Set terret.root to the directory containing source repositories. Terret puts managed linked checkouts under terret.worktreeRoot, which defaults to terret-worktrees under the server's java.io.tmpdir. Set an absolute checkout root outside the project tree if the operating system cleans that temp directory and the checkouts need to survive. The two roots must remain disjoint when symlinks resolve.

Use the MCP tool remove_worktree to retire a managed checkout. It leaves the branch and prunes stale worktree metadata in the source repository. Terret does not migrate or remove old sibling worktrees; manage them separately with Git. See Jobs for the tool inputs.

Local Grok launcher

The app wires SystemPerlProcessGroup.layer into Spawner.layer for local Grok launches. Spawner prepares the isolated environment and owns the launch scope. To embed Terret with a native supervisor or a test double, supply a different ProcessGroupLauncher layer to Spawner.layer. The Grok harness and its ACP adapter use the same injected spawner.

Documentation

./histos test proves the docs. Each page is a Scala program that asserts under the test run and then renders to the site, so a snippet that does not compile or does not hold fails CI. The catalog names specular-histos, and the build turns that site service on. A push to main publishes the site at earlyeffect.rocks/terret. Pull request CI builds the site and runs those doc tests so a stale or broken page fails review.

Scala.js UI tests

Install the declared test dependencies with npm ci --ignore-scripts. package.json pins jsdom, and the committed package-lock.json fixes its dependency graph. node_modules and linker output are gitignored. All application and test source is Scala; JavaScript is generated by the linker.

The build adds ui-test/src/test/scalajs only to the card and watch Scala.js test roots. Histos currently rejects JsEnv.Jsdom at runtime, so those modules retain JsEnv.Node and share a Scala test fixture that opens jsdom, installs DOM globals, closes the window, and restores the globals after each suite. DOM tests run sequentially because they share the process's document. The watch suites give each test its own Scope so listeners, fetches, and WebAuthn requests close before the DOM is released. Deterministic browser seams cover form interception, submit buttons, CSRF and exact-body binding, challenge encoding, signature conversion, safe navigation, denial, duplicate submission, and cancellation. They need no real passkey or biometric prompt. The browser bundles contain no jsdom dependency or Node bootstrap.

Both UI modules use the verification lane, so name them explicitly:

CI=true ./histos test card
CI=true ./histos test watch

Run the default lane locally with CI=true ./histos test --ignore-tag live-grok. The explicit filter keeps the live Grok cases out even if an existing Histos daemon omits the current caller's CI environment from test children. Select live cases individually by tag.

Check changed Scala files with ./histos fmt --check --file path/to/Changed.scala. Omit --file for a repository-wide check. Keep commands in the foreground and judge their exit status; --quick can skip tests.

Watch authentication

Choose one provider or combine them. Terret starts the watch listener on loopback when any provider is enabled. TERRET_WATCH_PORT selects its port (default 8081). For HTTPS, terminate TLS at a reverse proxy that preserves the browser Host and forwards to that port. When using Cloudflare Access, point cloudflared at the watch port and configure the Access application for its public hostname. If the Access policy gates the whole hostname, visitors must clear that policy before they can reach any sign-in option there. To offer independent login methods, use an ingress that lets those requests reach Terret.

For a local native-only setup:

export TERRET_WATCH_NATIVEPASSKEY=true
export TERRET_WATCH_ORIGIN=http://localhost:8081
export TERRET_PASSKEY_RPID=localhost
export TERRET_PASSKEY_ORIGINS=http://localhost:8081
export TERRET_PASSKEY_FILE=/absolute/private/directory/passkeys.json

Create the private directory on the host and give one Terret process ownership of the credential file. Start with the usual HTTP key configuration for /mcp. On an empty store, the server writes one high-entropy enrollment code to its startup error output. Protect that output. Browse to /watch/login, enter the code once, and complete registration within ten minutes. If an unused enrollment permit expires, the next startup with an empty store prints a new code. A successful first enrollment closes the bootstrap across restarts while the credential file is retained. Keep a backup of that file and enroll a second passkey using the first.

For GitHub, create a GitHub OAuth App with <TERRET_WATCH_ORIGIN>/watch/github/callback as the callback. Set TERRET_GITHUBAUTH_CLIENTID, TERRET_GITHUBAUTH_CLIENTSECRET, and TERRET_GITHUBAUTH_OWNER. Pick Sign in with GitHub, then Open watch after GitHub returns. Set TERRET_ACCESS_TEAM, TERRET_ACCESS_AUDIENCE, and TERRET_ACCESS_OWNER to add Cloudflare Access. A verified GitHub or Cloudflare owner can enroll the first passkey directly on /watch when the passkey origin and relying party are configured. See Config for all settings.

Watch bundle assembly and the session card

The app build packages the current /watch.js automatically. For local MCP Apps testing, link the session card:

CI=true ./histos run card --platform js

Copy the optimized card product from .histos/run/card/<scala>/js/full/<link-id>/linked/full.js to mcp/src/main/resources/terret/session-card.js. The product and assembled resource are gitignored. Without it, the card shell cannot mount its view. For a physical passkey test, configure the watch origin and relying-party ID, then enroll using the setup steps above. Use Touch ID or a WebAuthn hardware key that supports discoverable credentials. Then submit a watch action to verify the new passkey. Use your existing key to approve enrollment of a second authenticator. Set TERRET_PASSKEY_FILE to keep enrolled keys across restarts.

Check the assembled resource with:

CI=true ./histos test app --only terret.app.watch.WatchScriptSpec

That check compares the served resource with the assembled linker asset. The regular watch route tests also check its content type and security headers. No JavaScript source is maintained or committed.

See DESIGN.md for the decisions and ROADMAP.md for which phase is open.

Command.parse(Chunk("restart"))
Right(Invocation(Restart,None))
ServiceConfig.load(ServiceConfig.defaultRaw).map(_.supervisor)
Right(None)
ServiceConfig.load(ServiceConfig.defaultRaw.copy(supervisor = "launchd"))
Left(LabelsMissing)