Skip to content

feat: add pluggable local inference backends - #25

Merged
stuffbucket merged 5 commits into
mainfrom
worktree-local-inference-backends
Sep 1, 2026
Merged

stuffbucket merged 5 commits into
mainfrom
worktree-local-inference-backends

Conversation

@stuffbucket

@stuffbucket stuffbucket commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

What this adds

Pluggable local inference backends, loaded as trusted external plugins rather than compiled into the engine.

  • packages/maximal-provider-contract — side-effect-free HTTP gateway contract. Core depends on this and nothing else.
  • packages/maximal-dsh-host — generic in-process DeepSeek Harness (DSH) host that loads Cordis/DSH plugins from a user-managed profile directory.
  • packages/anthropic-provider, packages/omlx — independently installable stock adapters.
  • packages/llama-server — private descriptor scaffold, deliberately separate from maximal-electron's embedded node-llama-cpp utility process.

Rollout is reversible: the built-in Anthropic passthrough stays the default legacy mode; dsh mode is opt-in via providerHost.mode. Maximal never installs, upgrades, or rewrites profile packages. Composition is documented in packages/maximal/docs/provider-profiles.md.

Cordis supplies plugin lifecycle and dependency scoping — it is not a security boundary. Every package in a provider profile is trusted in-process code with Maximal's full filesystem, network, environment, and OS-user authority. That is stated in the docs rather than implied.

Also in scope: the workspace test graph moves behind a mountless, offline Docker boundary (pnpm test, docs/testing-in-docker.md) — no bind mount, no Docker socket, no forwarded host environment, --network=none, non-root, with host-state canaries verified after each run. scripts/verify-workspace.mjs gains check 7, asserting provider package dependency boundaries so a concrete adapter can never be compiled into Core, the DSH host, or the composition root.

Resync with main

Rebased onto 62572b9. Three conflicts needed hand resolution:

  • untrusted-frame move. This branch moves src/routes/untrusted-frame.ts to src/lib/http/untrusted-frame.ts; 62572b9 landed a new importer of the old path in routes/responses/handler.ts. Git's rename detection carried it — verified zero remaining references to ~/routes/untrusted-frame, and all importers resolve to the new path.
  • scripts/verify-workspace.mjs. Both sides added a check numbered 7. Kept this branch's provider-architecture check as 7 and took main's newer header text for the lockfile check, now 8. Sections renumber cleanly 1–9.
  • packages/maximal-core/package.json. Took main's dependabot pins (@hono/zod-openapi 1.6.0, citty ^0.2.2) alongside this branch's new @stuffbucket/maximal-provider-contract workspace dep.

The lockfile was regenerated from the merged manifests rather than hand-merged: +234 lines, exactly the five new importer entries, no churn elsewhere.

packages/maximal-core/dist/ is no longer committed (fdc8cb3). It was force-added here to serve bun add github:stuffbucket/maximal-core, an install path that belongs to the standalone repo — monimal's copy sits at packages/maximal-core/, and no package manager's git specifier addresses a subdirectory. SOURCES.md had already recorded the monorepo's position, and maximal-electron had already dropped its own. 46 files, 95,509 lines, 7.4 MB removed; bindings:check retired with them.

Fixed during the rebase

Four defects that only surface once the branch meets main's newer pins and a real CI run:

  • .github/workflows/ci.yml — this branch replaced pnpm run check with a bare turbo run build typecheck lint. turbo is a root devDependency and is not on PATH in a workflow run: block, so the step died with exit 127 before anything ran. Now pnpm exec turbo ..., matching every other step in the file.
  • packages/maximal-core/scripts/ops/check-ci-coverage.ts — the fix above then tripped ci:check, whose runsTurboTask only accepted a command starting literally with turbo run. That matcher is why the workflow used the bare form in the first place. It now unwraps a pnpm exec prefix, which is a direct invocation, while still failing closed on shell composition. Covered by new cases in its own test, including that pnpm run, pnpm dlx, npx, and pnpm exec echo are not accepted.
  • packages/maximal-core/tests/cli-composition.test.ts — the branch's new test built a ParsedArgs fixture against citty ^0.1.6. Taking main's ^0.2.2 means the type also requires the alias keys (p, v, a, r, w, g, c); added them.
  • turbo.json — lint depended only on topo, so type-aware rules raced the build. packages/maximal/src/provider-gateway.ts imports types from @stuffbucket/maximal-provider-contract and @stuffbucket/maximal-dsh-host, neither of which commits build output, so on a cold checkout lint saw unresolved types and emitted no-unsafe-* errors. lint now carries the same ^build dependency typecheck already had. Verified this is still required with Core's dist/ present: 53 errors without it.

Verification

Full graph in the container boundary — 15/15 tasks, exit 0, 0 failures:

Package Tests
maximal-core 1865 across 154 files
maximal 94 across 9 files
maximal-electron 59 files
maximal-client 54 across 9 files
maximal-dsh-host 43
anthropic-provider 23
omlx 20
maximal-site 17
maximal-provider-contract 4
llama-server 1
  • turbo run build typecheck lint — 29/29, exit 0, from a cold state (no dist/ for the new packages, no turbo cache) so the lint ordering fix is actually exercised.
  • check:deep:host — exit 0, including casts:check, knip, deps:check, dupes:check, ci:check, and typecheck:downstream.
  • verify:workspace — 14 assertions over 2700 things, 0 failed.

Note for reviewers running this locally

pnpm test may fail on a warm checkout with ERR_PNPM_TARBALL_URL_MISMATCH. Any pnpm run <script> re-resolves and writes ~1610 rotating ms-feed-N shard hosts into pnpm-lock.yaml before the script body runs; the Docker context then carries that poisoned lockfile into a --frozen-lockfile install that rejects it.

This is pre-existing environment behavior, not introduced here — main reproduces it identically (1602 entries) and its CI is green. The new harness just turns previously-invisible local churn into a hard failure, because it copies the working tree into the build context. Tracked in #26.

Workaround that produced the green runs above:

node scripts/strip-lockfile-hosts.mjs && node scripts/docker-test.mjs

Invoking the harness directly skips pnpm's pre-run re-resolution and keeps the context clean.

Load trusted provider plugins through the DSH host without bundling runtimes into Core, add oMLX and Anthropic adapters, and make configuration and gateway lifecycles reversible.

Run product tests in a disposable offline Docker boundary and harden CI, generated bindings, diagnostics, and host-state isolation.
@stuffbucket
stuffbucket force-pushed the worktree-local-inference-backends branch from 22f393d to 8b12a0a Compare August 31, 2026 22:39
@stuffbucket

Copy link
Copy Markdown
Owner Author

CodeQL: 7 new alerts, all in the committed bundle — needs a policy call

The build / typecheck / lint / test gate is green. The only failing check is CodeQL (3 high, 4 medium). Every alert is in one file:

$ gh api "repos/stuffbucket/monimal/code-scanning/alerts?pr=25&state=open" --jq '[.[].most_recent_instance.location.path] | unique'
["packages/maximal-core/dist/main.js"]

Zero are in any workspace src/. Each traces to a bundled dependency:

Rule Bundle line Origin
js/incomplete-sanitization (high) 4201 [email protected]/lib/command.js — arg.replace(DOUBLE_QUOTES_REGEXP, ...)
js/incomplete-sanitization (high ×2) 56354, 56358 [email protected] — destination.replace(/([<>()])/g, ...), title.replace(/"/g, ...)
js/overly-large-range (medium ×4) 72250–72251 [email protected]/dist/utils/cookie.js — /^[!#-:<>-[\]-~]+$/, the RFC 6265 token charset

Verified by grepping the identifiers against packages/*/src (no hits) and then against node_modules (hits as above).

Why it appears now

This is new because the branch commits packages/maximal-core/dist/main.js and CodeQL scans it. Main tracks no dist/, so it never had a bundle to analyze. It is not rebase fallout — it would have appeared on the first CI run of this branch as originally authored, and it will recur on every future PR that touches the bundle.

The bundle is not optional: bindings:check (new here via check:deep:host) requires the committed bundle and .d.ts to match a fresh build, because a git-dependency consumer of maximal-core runs those exact bytes with no build step.

Why I did not just fix it

ADR-0001 says rule-wide exclusions belong in .github/codeql/codeql-config.yml. That file does not exist in this repo, and neither does a codeql.yml workflow — CodeQL here is GitHub default setup, configured in repo settings. Adding a config file has no effect without switching to advanced setup, which is a repository settings change, not an in-repo one. Dismissing seven security alerts is likewise not a call I should make unilaterally.

Options

  1. Advanced setup with paths-ignore: packages/maximal-core/dist/** — stops analyzing generated bytes while keeping full coverage of src/. Matches ADR-0001's "never run this query on this path" carve-out, but requires disabling default setup in settings.
  2. Dismiss the seven as won't-fix (generated dependency code) — fastest, but recurs whenever the bundle is rebuilt and the rationale lives only in the Security tab, which ADR-0001 explicitly moved away from.
  3. Accept the red check on bundle-touching PRs.

Flagging rather than choosing — this is a security-policy decision.

…t suppressed

Committing `packages/maximal-core/dist/` makes every bundled dependency's
source into repo content that CodeQL analyzes as if we wrote it. Seven
alerts on #25 are entirely that: execa's escapedCommand formatter,
turndown's markdown link escaping, and hono's RFC 6265 cookie charset.

ADR-0001 prescribes inline `// codeql[...]` for by-design alerts, and
that mechanism cannot reach here -- the bundle is regenerated from
node_modules on every Core build, so a hand-added comment is erased and
`bindings:check` then fails on the diff. Its `query-filters` fallback has
nowhere to live either: monimal runs CodeQL default setup, which reads no
in-repo config, and the ADR's `links.codeql_config` pointer is inherited
from the maximal repo and dead here.

So the alerts are dismissed per-alert and the rationale lives in the
tree, which is what the ADR's original Context asked for. Records the
per-alert assessment, why the two existing mechanisms don't apply, and
the advanced-setup `paths-ignore` escape hatch that is deliberately not
taken.
@stuffbucket

Copy link
Copy Markdown
Owner Author

CodeQL: investigated, decision recorded, dismissals pending

All seven alerts are third-party code inside packages/maximal-core/dist/main.js.
None is in a workspace src/. Traced to the exact upstream module:

Alert Rule Line Origin Assessment
9 js/incomplete-sanitization (high) 4201 [email protected]/lib/command.js escapeArg feeds only getEscapedCommand, which builds the human-readable escapedCommand field on execa's result/error objects. execa spawns via cross-spawn with an argv array, never a shell — a display formatter, not a sanitizer. False positive
10, 11 js/incomplete-sanitization (high) 56354, 56358 [email protected] escapeLinkDestination / escapeLinkTitle escape markdown for output. Not a security boundary; any real gap is upstream's. Won't fix
5–8 js/overly-large-range (medium) 72250–72251 [email protected]/dist/utils/cookie.js [!#-:<>-[\]-~] is the RFC 6265 cookie-name / cookie-octet charset, written deliberately as ranges. False positive

Why this branch and not main

main tracks zero files under packages/maximal-core/dist/. This branch commits
the bundle for the first time, so all seven land as new alerts and trip the
gate. main has three open alerts of its own (now #28) and its gate still passes
— the check compares against the base, not against zero.

Why dismissal, and not one of ADR-0001's mechanisms

  • Inline // codeql[...] cannot survive. The bundle is regenerated from
    node_modules on every Core build. A hand-added comment is erased on the next
    build and bindings:check then fails on the diff between the annotated file and
    the fresh one. The mechanism works because the comment travels with source we
    own; there is nothing here for it to attach to.
  • query-filters has nowhere to live. GET /code-scanning/default-setup
    returns state: configured — monimal runs CodeQL default setup, which reads
    no in-repo configuration. ADR-0001's links.codeql_config pointer at
    .github/codeql/codeql-config.yml is inherited from stuffbucket/maximal; that
    path does not exist here and creating it would be inert.
  • Advanced setup with paths-ignore: packages/maximal-core/dist/** would end
    this class permanently, but costs an owned codeql.yml plus a repository-settings
    migration off default setup, and silences the bundle wholesale rather than one
    reviewed finding at a time. Deliberately not taken.

e97fe74 records all of the above as an amendment to maximal-core ADR-0001, so the
"why" is greppable in the tree rather than living only in the Security tab. That
is the only file the commit touches — no build, CI, or workflow changes.

What still needs doing

The seven dismissals themselves. They are a security_events: write action that
this session is not permitted to perform, so they need either a granted permission
or seven dismissals in the Security tab, using the reasons in the table above.

The bundle was force-added so that `bun add github:stuffbucket/maximal-core`
yields a working `maximal` command with no toolchain: `bin` points at the
committed bytes, and Bun's installer blocks dependency lifecycle scripts, so an
install-time build leaves a dangling symlink. That reasoning is sound and it
belongs to the standalone maximal-core repo. It does not reach monimal — the
package sits at packages/maximal-core/, and no package manager's git specifier
addresses a subdirectory, so the install path it exists to serve cannot be
exercised against this repo at all. The commits check-bindings.ts cites as the
decision's origin, f79f7b6 and d607485, are not in this repository's history.

monimal had already taken this position once. SOURCES.md records that `build`
was extended with `build:lib` "so the subpath exports in its `exports` map
resolve without committing `dist/lib`", and maximal-electron dropped its own
committed dist. maximal-core was the last package in the workspace carrying
one: 46 files, 95,509 lines, 7.4 MB, roughly 5 MB of it gpt-tokenizer BPE
tables.

Nothing ever verified against it. `.dockerignore` excludes dist, and the image
build runs `turbo run build`, so the container suite has always tested a freshly
built bundle rather than the committed one.

Retires `bindings:check`, which compared a committed copy against a fresh build
and has nothing left to compare. `scripts/ops/check-bindings.ts` itself stays:
nine modules import ARTIFACTS, MAIN_BUILD_ARGV, GitRunner and realGit from it.

Publishing is unchanged. `files`, `exports` and `bin` still name dist/, and
`prepack` builds into it before packing, so the GitHub Package Registry path is
untouched.

This also removes the seven CodeQL alerts on this PR at the source rather than
dismissing them. All were third-party code the bundler had inlined — execa's
escapedCommand formatter, turndown's markdown link escaping, hono's RFC 6265
cookie charset — and none was in a workspace src/. ADR-0001's amendment now
records that, in place of the dismissal policy it briefly carried.
@stuffbucket

Copy link
Copy Markdown
Owner Author

Resolved — superseding the dismissal plan above

Both earlier comments asked for seven alerts to be dismissed. Don't; that is no
longer the right move and nothing needs dismissing.

The seven alerts existed only because this branch committed
packages/maximal-core/dist/, which inlines node_modules and so turns every
dependency's source into repo content CodeQL analyzes as if we wrote it. The
bundle was force-added to serve bun add github:stuffbucket/maximal-core — an
install path that belongs to the standalone repo. monimal's copy sits at
packages/maximal-core/, and no package manager's git specifier addresses a
subdirectory, so that path cannot be exercised here at all. Confirmed with Brian
that monimal will not be split back out.

SOURCES.md had already recorded the monorepo's position — build was extended
with build:lib "so the subpath exports in its exports map resolve without
committing dist/lib" — and maximal-electron had already dropped its own.
maximal-core was the last package in the workspace carrying one. Nothing verified
against it either: .dockerignore excludes dist, and the image build runs
turbo run build, so the container suite always tested a freshly built bundle.

fdc8cb3 untracks it: 46 files, 95,509 lines, 7.4 MB (~5 MB of it gpt-tokenizer
BPE tables). bindings:check is retired with it — it compared a committed copy
against a fresh build and has nothing left to compare. scripts/ops/check-bindings.ts
stays; ten modules import ARTIFACTS, MAIN_BUILD_ARGV, GitRunner and
realGit from it. Publishing is untouched: files, exports and bin still
name dist/, and prepack builds into it before packing.

Result — all seven alerts closed as fixed, none dismissed:

11  js/incomplete-sanitization  fixed
10  js/incomplete-sanitization  fixed
 9  js/incomplete-sanitization  fixed
 8  js/overly-large-range       fixed
 7  js/overly-large-range       fixed
 6  js/overly-large-range       fixed
 5  js/overly-large-range       fixed

Every check is green. Analyze (javascript-typescript) also dropped from 2m46s
to 1m22s, no longer parsing a 7.4 MB bundle.

Verified before push: check:deep:host exit 0 without the gate (knip, ci:check,
build, downstream contract typecheck); turbo run build typecheck lint 29/29;
verify:workspace 14/14; container graph 15/15 exit 0 (maximal-core 1865 tests,
0 fail; 2151 across ten packages).

Still open and unrelated: #28 (three CodeQL alerts on main), #26 (pnpm run
re-resolves the lockfile), #27 (stale eslint-disable).

@stuffbucket stuffbucket changed the title Add pluggable local inference backends feat: add pluggable local inference backends Sep 1, 2026
@stuffbucket
stuffbucket merged commit 64b9106 into main Sep 1, 2026
6 checks passed
@stuffbucket
stuffbucket deleted the worktree-local-inference-backends branch September 1, 2026 20:33
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.

1 participant