Skip to content

LM-2: secure local connections and bounded model discovery (#378) - #386

Closed
BunsDev wants to merge 6 commits into
mainfrom
lm2-discovery
Closed

BunsDev wants to merge 6 commits into
mainfrom
lm2-discovery

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Part of #378 (LM-2) under #376. Draft: completion is blocked on #377 (LM-1), which is not accepted.

Main-owned, loopback-only local-model connection profiles and bounded metadata discovery. There is no UI, no execution binding and no inference.

What's here

  • main/engine/local-models/endpoint-policy.ts: same-machine HTTP(S) origins only (localhost, 127.0.0.0/8, ::1 and their alternate spellings). localhost resolutions are re-checked at connect. Redirects, credentials in the URL, queries, fragments and unexpected paths are refused. Requests have a deadline, a byte cap and cancellation, and failure text is fixed.
  • main/engine/local-models/connections.ts: profiles in app/local-connections.json with no secrets. Optional tokens go in the existing SecretStore as local_connection:<id>. The revision moves when the runtime, address or token changes. A token never follows a changed address, stale edits are refused, and deletion leaves a tombstone that never resolves.
  • main/engine/local-models/discovery.ts: Ollama (/api/tags, /api/ps, /api/show capped at 32), LM Studio (/api/v0/models, falling back to /v1/models) and Responses-compatible servers (/v1/models).
    • Model IDs are kept exactly as reported.
    • Installed, loaded, kind and advertised states are filled only when the runtime reports them; otherwise they are unknown.
    • Embedding-only, non-text and Ollama cloud models can't be selected.
    • Manual IDs are kept when discovery fails.
    • Results arriving after a newer read, a cancel, an edit or a deletion return stale.
  • main/engine/local-models/service.ts and shared/local-connections.ts: one local-models:command channel with a strict validator, registered localOnly. The Store desktop offline demo refuses it.

Evidence (fixture-only)

All of it comes from synthetic loopback servers. No real Ollama, LM Studio, vLLM or llama.cpp was contacted, and no model was loaded, pulled or run. Details are in docs/reviews/2026-10-22-lm2-connections-discovery.md.

  • AC1: normal, empty, malformed, wrong-shape, unavailable, 401, slow and oversized fixtures, through the compiled main handler and through the production Electron preload and ipcMain (e2e/local-models-ipc.spec.ts).
  • AC2: non-loopback addresses, 0.0.0.0/::, link-local, IPv4 and IPv6 alternate spellings, injection characters, redirects, a localhost that resolves off-machine (zero requests reach the server) and forged IPC fields.
  • AC3: the token never appears in IPC replies or the profiles file, and is never stored in plain text. A cloud typesafe_api_key is never sent. Without an OS keychain, saving a token is refused.
  • AC4: the same ID on two connections yields two targets. Results arriving late after an edit, switch or delete are stale.
  • AC5: manual IDs stay available and selectable; embedding-only and cloud models don't.
  • AC6: every fixture asserts its exact request list, and none is an inference, pull, load or unload route. Deleted or edited profiles never resolve an old revision.

Checks at 1c0dd37 (code); ef6863e adds docs only

Node v24.22.0, pnpm 10.34.5, Electron 44.4.5, Playwright 1.63.0.

Open gates

Do not merge. No release.

🤖 Generated with Claude Code

BunsDev and others added 5 commits October 22, 2026 18:41
Same-machine HTTP(S) origins only; localhost resolutions re-checked at
connect; redirects, credentials-in-URL, queries and unexpected paths
refused; deadline, byte cap and cancellation; fixed error text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Profiles live in app/local-connections.json without secrets; optional
tokens use the existing SecretStore under local_connection:<id>. The
renderer view carries presence only. Revisions move when runtime,
address or token change; a token never follows a changed address;
stale edits are refused; deletion leaves a non-resolving tombstone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ollama (tags/ps/capped show), LM Studio (/api/v0/models, /v1 fallback)
and Responses-compatible (/v1/models) metadata reads only. Exact IDs,
installed/loaded/kind/advertised states or unknown, cloud-routed and
embedding models unselectable, manual IDs kept on failure. Size, count
and time bounds; superseded, edited or deleted reads return stale.
The resolver test seam is always wrapped by the loopback check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
local-models:command validates request shape strictly and is registered
localOnly; edits and deletes invalidate in-flight discovery. Store
desktop's offline demo refuses it. Adds a production-IPC Electron spec,
the dated review receipt and the status entry; completion stays blocked
on #377.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 23, 2026 4:38am UTC

Request Review

@github-code-quality

github-code-quality Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 584aa1a lm2-discovery 3654053 +/-
65% 65% 0%
View coverage of the 9 most impacted files.
File main 584aa1a lm2-discovery 3654053 +/-
apps/store-desk...rc/main/demo.ts 95% 95% 0%
apps/desktop/sr...gine/plugins.ts 97% 97% 0%
apps/desktop/sr...gine/secrets.ts 100% 100% 0%
apps/desktop/sr...shared/types.ts 100% 100% 0%
apps/desktop/sr...dels/service.ts 0% 95% +95%
apps/desktop/sr.../connections.ts 0% 100% +100%
apps/desktop/sr...ls/discovery.ts 0% 100% +100%
apps/desktop/sr...point-policy.ts 0% 100% +100%
apps/desktop/sr...-connections.ts 0% 100% +100%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 23, 2026 05:09 UTC

@BunsDev

BunsDev commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

The two review defects (P1: a failed profile write changed an old revision's credential; P2: metadata could reflect the token into IPC) are fixed with failing-first regressions in #398. It replays this PR's commits onto main unchanged. This branch is still claimed by another session, so I didn't push to it. Close whichever PR you don't keep.

BunsDev added a commit that referenced this pull request Oct 24, 2026
…378)

Val accepted Gate A narrowly on 2026-10-24 for main at bb0e1a4: the
LM-1 contract (#397, #400) and the recorded Strata combination only (see
the acceptance comment on #377). local-models.md, both status bullets
and the LM-2 receipt now say so instead of "not accepted", and list
what remains open: native Ollama/LM Studio metadata reads, the AGENTS.md
network wording, the #386/#398 choice and the landing order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
BunsDev added a commit that referenced this pull request Oct 24, 2026
BunsDev added a commit that referenced this pull request Oct 24, 2026
#405 recorded Val's Gate A acceptance and approval of the AGENTS.md
metadata boundary, plus a CLI inventory with no local generative model.

Resolutions:
- docs/local-models.md keeps main's status line. The adoption paragraph
  now says #403 adopted the contract and that #386 and #398 are
  superseded.
- docs/status.md keeps main's LM-1 entry, which now says LM-2 consumes
  it through #403. The LM-2 entry records the approved boundary and
  says LM-2's discovery has not yet run against a real runtime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@BunsDev

BunsDev commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded: this work landed on main through #403 as e17aebd2fd4a2c691ee4e8946b5c2ef767aa023a, a single squash of #398's commits, #402's hardening and the LM-1 adoption. Closing so it isn't merged separately. The branch and its worktree are left as they are, and the PR can be reopened if needed.

@BunsDev BunsDev closed this Oct 24, 2026

This branch was successfully deployed

1 active deployment
Preview — 3654053f Deployed Oct 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants