mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 03:39:33 +01:00
feat(local-model): contract for the install stage (types, stubs, fake runtime)
The types, the module skeletons and the test fake that let the runtime, the install job and the window be built at the same time. Types: - src/types/local-model-install.ts (new): the runtime pin, the install states, steps and error codes with one sentence and one next step each, the progress, the `install` object of GET /api/local-model, the bodies and 409 answers of the install verbs, the state file. `LocalModelStatus` moves here; `install` is optional until the route emits it. - src/types/local-model.ts: the catalogue row's Mac memory figures, the measured speed of a tested entry, the `measured` budget source, `RecommendOptions`, and the row tag, the coding agents and the install total of a candidate. All optional until the catalogue and `recommend()` carry them, so the read-only stage keeps compiling and its tests stay green. Modules with final signatures and bodies that throw: runtime.ts (the compiled pin is final), ollama-client.ts, developer-tools.ts, state-store.ts, install-job.ts (the state, step and transition tables are final), connect.ts, custom-model-hosts-writer.ts, cli-install-runner.ts. Nothing imports them yet, so the server is unchanged. Implemented: paths.ts (every folder of the feature, from dataPath()), and `modelFitsBudget()` in recommend.ts, the judgement the job makes with the measured budget before it downloads a model. `recommend()` takes the options parameter and does not read it yet. Test fake: test/fixtures/fake-ollama.ts, a runtime on a port the system picks, in the shapes measured on a Mac: version, tags, ps, the pull stream (MLX and GGUF lines, an error line, a cut stream, a resumed pull), chat with and without a tool call, the model list, a runtime archive with Range support, and a fake child process that logs the device total. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
66ca92f7cf
commit
771072c36b
17 files changed
+3770
-23
No files matched your search
@@ -71,6 +71,7 @@ import {
|
||||
type LocalModelMessage,
|
||||
type NoneReason,
|
||||
type Recommendation,
|
||||
type RecommendOptions,
|
||||
type SpeedGrade,
|
||||
} from '../types.js';
|
||||
import { chipBandwidthGbps } from '../config/local-model-catalog.js';
|
||||
@@ -135,6 +136,29 @@ function fitGrade(need: number, budgetBytes: number): FitGrade {
|
||||
return 'out';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the catalogue model `modelId` at `context` tokens fits this Mac's budget (a `good`
|
||||
* or a `tight` fit). The install job asks this right after the runtime started, with the
|
||||
* budget the runtime measured, BEFORE it downloads the model: a `false` ends the job with
|
||||
* `does-not-fit`. It is the same judgement `recommend()` makes for a candidate, without the
|
||||
* ranking, so a model that fits is never ruled out for being listed sixth.
|
||||
*
|
||||
* `options` is the stage 2 input, as for `recommend()`; nothing reads it yet, so the budget
|
||||
* is still the estimate. False for a model the catalogue does not have.
|
||||
*/
|
||||
export function modelFitsBudget(
|
||||
hw: HardwareFacts,
|
||||
catalog: LocalModelCatalog,
|
||||
modelId: string,
|
||||
context: number,
|
||||
options: RecommendOptions = {}
|
||||
): boolean {
|
||||
void options;
|
||||
const model = catalog.models.find((entry) => entry.id === modelId);
|
||||
if (!model) return false;
|
||||
return fitGrade(needBytes(model, context, catalog, hw), deviceBudget(hw).budgetBytes) !== 'out';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the MACHINE is Apple silicon. `hw.optional.arm64` decides when it was read. Without
|
||||
* it: a process under Rosetta, an arm64 process or an Apple chip name each prove Apple silicon
|
||||
@@ -256,12 +280,18 @@ function none(
|
||||
/**
|
||||
* The recommendation for this Mac. `harnessFacts` holds one fact per catalogue harness the
|
||||
* caller could resolve; a catalogue harness without a fact is not offered.
|
||||
*
|
||||
* `options` is the stage 2 input (`RecommendOptions`: the budget the runtime measured, and
|
||||
* the runtime download an install still needs). The parameter is in place so callers compile
|
||||
* against the final signature; nothing reads it yet.
|
||||
*/
|
||||
export function recommend(
|
||||
hw: HardwareFacts,
|
||||
catalog: LocalModelCatalog,
|
||||
harnessFacts: readonly HarnessFact[]
|
||||
harnessFacts: readonly HarnessFact[],
|
||||
options: RecommendOptions = {}
|
||||
): Recommendation {
|
||||
void options;
|
||||
// Off macOS and on an Intel Mac there is no budget to compute: a model has no memory to run in.
|
||||
const noBudget: DeviceBudget = { limitBytes: 0, budgetBytes: 0, source: 'estimated' };
|
||||
if (hw.platform !== 'darwin') return none('not-macos', noBudget);
|
||||
|
||||
Reference in new issue
Block a user