feat: certified local mode — managed on-device model with verified setup and egress guard - #1163
Open
anandgupta42 wants to merge 21 commits into
Open
feat: certified local mode — managed on-device model with verified setup and egress guard#1163anandgupta42 wants to merge 21 commits into
anandgupta42 wants to merge 21 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #1162
Type of change
What does this PR do?
Adds
altimate local— a managed local-model mode. One command detects hardware, downloads a SHA-256-pinned GGUF +llama.cppruntime, starts a loopback-only server, runs certification probes (tool-call round trip, reasoning render, 8K prefill), and only then wires alocalprovider into the user config. Subcommands:models,status,stop,doctor,update.Design decisions worth knowing when reviewing:
wire.ts): wiring addsaskrules forwebsearch/webfetch/codesearch. This works because user config merges after agent rulesets and permission evaluation is last-match-wins, so a config-levelaskoverrides the agents' built-inallow. Rules are only added where the user has no existing key;--no-egress-guardremoves only rules a prior guarded wiring actually set (ownership recorded in local mode's ownenvironment.json, not the user config — kept out of the config schema on purpose).small_modelpinned to local when unset so title generation never silently calls a cloud model. Compaction already follows the session model, so it needs no pin.recipes.jsonis amodels[]registry with per-tier recipes;--model <id>selects,firstModelis only the default. Adding future models is a data change.system.ts, gated on the existingALTIMATE_TOOL_RETRIEVALenv): descriptions compact to their first sentence in the system prompt. Behavior with the flag unset is byte-identical to today. Measured on an M4 Max: first-turn input 33.4K → 28.0K tokens, wall 4:48 → 3:39.fitHead,uncountedTailoverflow estimation (with the fitHead 0.8 margin), tool-callid sanitization, sharedtruncate-core, and honest run accounting (run-accounting.ts) including an idempotent clientmessageIDon run retries (server upserts by id, so an ambiguous network failure can't double-execute a turn).local_model_info_shown/local_model_choice) is threaded through the tui-union /Telemetry.Event/ onboarding-extract / compile-time parity test — those four must stay in sync.Provenance: this is a content-only re-port of the earlier local-mode work (originally developed on a branch that could not be pushed) with three review rounds applied on top — 16 confirmed findings fixed, including a lock that could loop forever on fresh installs, certification durations measured before the await, docker daemon errors read as "container absent", and a disk-space discount that keyed on any cached
.ggufinstead of the target artifact.How did you verify your code works?
altimate localsetup ran green after every fix — detect → SHA-verify → serve → certify (3/3 probes) → wire.status/doctor/stop/restart cycle exercised. Real agent turns answered by the local model throughaltimate run, including after themessageIDretry change.webfetchproducedpermission requested: webfetch (…); auto-rejecting, and abash curlattempt was likewise gated. In the interactive TUI the same event renders as an approval prompt.test/local/(lock, runtime, hardware, preflight, docker, server, certify, wire, recipes, fetch), session compaction/uncounted-tail, truncate-core, run-accounting, onboarding telemetry, and the TUI welcome-dialog tests. Typecheck clean inpackages/opencodeandpackages/tui.bun run script/upstream/analyze.ts --markers --base main --strictgreen.mkdocs build --strictgreen.docker-sglangtier on real hardware (covered by injectable-exec unit tests only), Linux AMD/Intel GPU auto-detection (known gap — runtime works via Vulkan, docs say exactly that), and the TUI picker row was verified by component tests, not visually in a live terminal.Screenshots / recordings
Terminal transcript of the real setup run (M4 Max):
Live egress-guard probe (headless run auto-rejects; TUI shows an approval prompt):
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_019zce4wWoFV7SNti1nfhq5q
Note
High Risk
Adds managed downloads, Docker GPU containers, and config/permission wiring plus changed
runexit semantics and retries—areas that affect security posture and CI automation.Overview
Introduces
altimate local— a new CLI surface that detects hardware, runs preflight, downloads SHA-256–pinned model/runtime artifacts (llama.cpp or DGX Spark SGLang in Docker), starts a 127.0.0.1-only server, certifies it (tool-call, reasoning, 8K prefill) before touching config, then wires alocalprovider (with optional egress guardaskrules for web tools). Subcommands covermodels,status,stop,doctor, andupdate; startup callsapplyLocalEnvironment()so later commands pick up persisted local defaults.Headless
runharness gets a dedicatedrun-accountingmodule: compaction steps no longer count toward--max-turns, termination is split intowhy_model_stopped/why_harness_stopped, session errors serialize cleanly, prompt enqueue uses bounded retries with a stablemessageID, the event subscription is abortable on fatal failure, andprocess.exitCode = 1on budget exhaustion or unrecovered errors.Onboarding telemetry adds
localas a curated provider,local_model_*events, andlocal_model_backon the model picker;compaction_head_truncatedis a new event type. Docs/README/quickstart/security/network/permissions expand around Local Mode; the builder prompt adds a mandatory finish protocol (re-read contract, run final build/tests)..gitignoreaddsdocs/site/.Reviewed by Cursor Bugbot for commit ba3ee0e. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds
altimate local— detects hardware, downloads SHA-256-pinned GGUF andllama.cppartifacts, certifies a loopback-only server, and wires alocalprovider into user config only after setup passes. Closes #1162.Egress guard and config wiring
askrules forwebsearch,webfetch,codesearch; user config merges last, so the guard overrides agent built-inallowrules, and the key-absent check evaluates the effective permission across config files in precedence order.provider.localblocks are deep-merged rather than replaced, so custom options and extra models survive re-wiring;--no-egress-guardremoves exactly the keys a prior wiring added, tracked per-key inenvironment.jsonand carried across re-runs.small_modelpins to local when unset, so title generation never calls a cloud model; compaction already follows the session model.Session and tool fixes riding along
fitHead(empties head when context ≤ headroom),uncountedTailoverflow estimation, deterministic tool-call-id sanitization, shared truncate-core, SGLang overflow detection.ALTIMATE_TOOL_RETRIEVALcompact descriptions to their first sentence; byte-identical without the flag.messageID; re-delivery returns the existing message, unrecovered mid-stream or terminal overflow errors exit nonzero, and only a trailing explicit DONE counts as termination.Written for commit ba3ee0e. Summary will update on new commits.
Summary by CodeRabbit
altimate localfor certified, API-key-free local model setup and inference.