feat: add model-only offline mode

AN
5h ago
+2743-66

Issue for this PR

Closes #1802

Type of change

  • New feature
  • Documentation

What does this PR do?

Adds an offline mode for running Altimate Code against a local or self-hosted model. With it on, Altimate Code sends network requests only to the configured model endpoint. Turn it on with ALTIMATE_OFFLINE=1 or "offline": true in a global or project config file.

With offline mode off, behavior is unchanged. Startup does one cheap check of the config files for the setting. Nothing else runs: fetch, proxy variables, the skill cache and the shell environment stay as they are.

Keeps working offline

  • DuckDB and SQLite files, and host-addressed warehouses (Postgres, MySQL, SQL Server, ClickHouse, Trino, Oracle, MongoDB) at localhost, 127.x, ::1 or a Unix socket. Other hosts, unparseable strings, SSH tunnels, cloud sign-in and account-addressed warehouses (Snowflake, BigQuery) are refused.
  • dbt on a local profile and target. dbt-duckdb can use installed extensions, local attachments and plugins. Remote storage (s3, https, gcs, md) is refused.
  • DuckDB still loads installed extensions, but never downloads new ones.
  • Shell, installed language servers, stdio and loopback MCP servers, tool run --daemon.
  • Git diffs, snapshots and revert, and worktree create, reset and remove.
  • attach to a server on this machine.

Blocked, with a one-line error or a skip: telemetry, account and remote config, the model catalog, update checks, workspace sync, session sharing, the web, search and feedback tools, remote MCP and MCP sign-in, automatic installs, dbt deps and dbt usage reporting, Git commands that use a remote, and commands that need a remote service.

How it works: a single module provides the switch, a fetch guard that allows only loopback, a model fetch pinned below the provider's explicit baseURL, and a literal loopback check. About 25 call sites check the switch.

  • Model requests go through the user's HTTPS_PROXY. Offline mode adds only localhost,127.0.0.1,[::1],0.0.0.0 to NO_PROXY, because Bun would otherwise send loopback requests through the proxy.
  • Programs the user runs are not sandboxed; the docs say so. They inherit ALTIMATE_OFFLINE=1.

Simplified in this revision: removed the global proxy bypass and its per-spawn restore. Also removed the skill cache restructure, typed policy errors and their HTTP 400 mapping, the shared-session delete changes, and the snapshot pin logic. The Git LFS env injection, the dbt version probes, per-protocol warehouse host parsing, and the attach/submodule special cases are gone too. Diff size: 119 files +3,731 before, 83 files +2,743 now (source +1,525 → +988, 83 → 59 files).

Startup only: offline mode turns on at startup, from ALTIMATE_OFFLINE=1 or a config file that startup checks (project, global and managed directories, OPENCODE_CONFIG_CONTENT). A config that asks for offline mode but is seen only later (macOS MDM preferences, remote well-known or legacy TOML config, or a project loaded by a server started without it) refuses to start, with a message to restart with ALTIMATE_OFFLINE=1.

Known limits (documented, declined bot findings): not checked by design: libpq env vars (PGHOSTADDR), Git partial-clone fetches and LFS downloads outside worktree reset, explicit DuckDB INSTALL, remote skill URLs, and a TUI bound to a LAN hostname. Offline MongoDB needs direct_connection: true.

How did you verify your code works?

  • End-to-end CLI runs against a fixture model endpoint, under all three opt-in paths (env, interpolated config content, project file). Every proxy variable points at a proxy that records and refuses requests, and PATH shims log git, npm, dbt, pip, curl, ssh and gh. Each run asserts zero non-model requests, no proxy hits and no network program runs.
  • A real HTTPS model endpoint reached through a CONNECT proxy set in HTTPS_PROXY. The proxy saw only the model host.
  • Offline off: fetch is not replaced, and the shell sees the user's own NO_PROXY, HTTPS_PROXY and no ALTIMATE_OFFLINE. The skill cache stays at cache/skills/<name>.
  • Unit tests: warehouse and dbt profile policy, the fetch guard and model fetch, git refusal, worktree reset, snapshots, npm, models, upgrade, small model, and dbt probes skipped.
  • Typecheck for opencode and core; upstream marker check; tracker leak check.
  • Local independent review after each push (Claude reviewer; Codex is out of quota); findings fixed or declined above.

Cost side effects

None.

Screenshots / recordings

No visual changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

šŸ¤– Generated with Claude Code