@octocodeai/freellama 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -0
- package/bin/freellama.mjs +69 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# `freellama` CLI package
|
|
2
|
+
|
|
3
|
+
This package is prepared to publish the `freellama` command through npm. Version 0.1.0 is not
|
|
4
|
+
published to a registry. In a checkout after `yarn install`, `npx` resolves the workspace package;
|
|
5
|
+
otherwise, use the release binary built at `target/release/freellama`. The JavaScript launcher
|
|
6
|
+
locates the compiled Rust binary and hands the current process to it. Routing and execution logic
|
|
7
|
+
remain in [`freellama-core`](../rust-core/README.md).
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
flowchart LR
|
|
11
|
+
N["npx @octocodeai/freellama …"] --> J["Node launcher"]
|
|
12
|
+
J -->|"optional platform package"| V["@octocodeai/freellama-native-<target>/freellama"]
|
|
13
|
+
J -->|"repository checkout"| T["target/release/freellama"]
|
|
14
|
+
V --> R["Rust CLI"]
|
|
15
|
+
T --> R
|
|
16
|
+
R --> C["freellama-core"]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Run it
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @octocodeai/freellama doctor
|
|
23
|
+
npx @octocodeai/freellama auth-token --out ~/.local/share/freellama/auth.token
|
|
24
|
+
npx @octocodeai/freellama serve \
|
|
25
|
+
--recommendation-catalog recommendations.example.toml \
|
|
26
|
+
--auth-token-file ~/.local/share/freellama/auth.token \
|
|
27
|
+
--feedback-file ~/.local/share/freellama/feedback.json
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`doctor` works without the control plane. It reports Ollama reachability, CLI/server version drift,
|
|
31
|
+
portable host hardware and disk discovery, effective settings, a non-mutating
|
|
32
|
+
`local_conservative_config_posture`, and source/permission-aware runtime signals. `memory_bytes`
|
|
33
|
+
is total host RAM; `unified_memory_bytes` is present only when the memory is known to be shared with
|
|
34
|
+
the accelerator. In another terminal, inspect or execute:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx @octocodeai/freellama models
|
|
38
|
+
npx @octocodeai/freellama route --task coding --objective fastest
|
|
39
|
+
npx @octocodeai/freellama task --task completion --objective fastest "Reply with exactly OK."
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Read the repository [CLI reference](../../docs/CLI.md) for the complete command map, task kinds, routing
|
|
43
|
+
confidence, policy generation, and admission controls.
|
|
44
|
+
|
|
45
|
+
## Run separate CPU and GPU backends
|
|
46
|
+
|
|
47
|
+
`serve` can assign exact models to a second loopback Ollama process:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npx @octocodeai/freellama serve \
|
|
51
|
+
--upstream http://127.0.0.1:11434 \
|
|
52
|
+
--cpu-upstream http://127.0.0.1:11436 \
|
|
53
|
+
--cpu-model nomic-embed-text:latest
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Managed tasks for assigned models use the CPU backend; other managed models and raw Ollama
|
|
57
|
+
passthrough use the primary backend. See [CPU and GPU model routing](../../docs/CPU_GPU_ROUTING.md)
|
|
58
|
+
for the process setup, verification steps, and measured concurrency result.
|
|
59
|
+
|
|
60
|
+
The primary admission pool defaults to two weighted units and the independent CPU pool to one.
|
|
61
|
+
These are conservative work-cost limits, not values derived from the development machine. Override
|
|
62
|
+
them with `--max-concurrent-tasks` and `--cpu-max-concurrent-tasks`. `route`, `recommend`, and
|
|
63
|
+
`task` also accept `--execution-preference auto|prefer-cpu|prefer-gpu`; this only chooses among
|
|
64
|
+
models already eligible on the requested backend and reports any fallback in the execution receipt.
|
|
65
|
+
`--min-placement-evidence observed` fails closed unless resident `/api/ps` evidence matches; use
|
|
66
|
+
the default `configured` for the first bounded warm-up.
|
|
67
|
+
|
|
68
|
+
The health endpoint advertises the backend, guarded-preference, and three-sample runtime-feedback
|
|
69
|
+
contracts plus per-backend admission capacity. Treat a missing contract as a stale running binary,
|
|
70
|
+
then rebuild and restart before testing placement.
|
|
71
|
+
|
|
72
|
+
Authentication covers both control routes and raw Ollama passthrough. A nonloopback listener also
|
|
73
|
+
requires `--allow-remote`; terminate TLS and add tenant authorization outside FreeLlama. The CLI
|
|
74
|
+
persists bounded aggregate feedback by default. Use `--ephemeral-feedback` only for disposable
|
|
75
|
+
runs. See the [production runbook](../../docs/PRODUCTION.md).
|
|
76
|
+
|
|
77
|
+
## Build the launcher and binary
|
|
78
|
+
|
|
79
|
+
Run `npx @octocodeai/freellama init` for a side-effect-free first-run receipt: it checks Ollama, inventories
|
|
80
|
+
installed tags, inspects serve health, and prints the next steps without downloading anything.
|
|
81
|
+
|
|
82
|
+
From the repository root:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
yarn install
|
|
86
|
+
yarn build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`yarn build` compiles the host Rust release binary. In a checkout, the launcher uses
|
|
90
|
+
`target/release/freellama`. Published installs resolve a matching optional platform package, such
|
|
91
|
+
as `@octocodeai/freellama-native-linux-x64-gnu`; no Rust toolchain is needed by the consumer.
|
|
92
|
+
|
|
93
|
+
Supported prebuilt targets are macOS arm64/x64, Linux arm64/x64 on glibc or musl, and Windows
|
|
94
|
+
arm64/x64. On an unsupported platform or an install made with `--omit=optional`, the launcher
|
|
95
|
+
reports the attempted packages and tells the operator to run `cargo build --release`. Node.js 20
|
|
96
|
+
or newer is required.
|
|
97
|
+
|
|
98
|
+
## Test packaging behavior
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
yarn workspace @octocodeai/freellama test
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The launcher tests cover binary selection, argument and signal forwarding, unsupported-platform
|
|
105
|
+
errors, and the files included in the package. Core CLI contracts live in
|
|
106
|
+
`packages/rust-core/tests/cli_contract.rs`.
|
|
107
|
+
|
|
108
|
+
## Understand CLI and MCP differences
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npx @octocodeai/freellama tools
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The output is contract-tested against the MCP server source. `delegate_research` and the online
|
|
115
|
+
model-library view are MCP-only. Control-plane startup, proxy startup, sessions, recommendation,
|
|
116
|
+
benchmarks, policy generation, and frozen-suite comparison are CLI-only.
|
|
117
|
+
|
|
118
|
+
Use the surfaces together: the CLI starts and verifies the local services; MCP lets an agent inspect
|
|
119
|
+
that state and submit bounded work. An installed MCP client can read `freellama://docs/index` and
|
|
120
|
+
fetch one packaged guide on demand. The CLI package links the checkout documentation; the MCP
|
|
121
|
+
package bundles the root `docs/` set for installed agent clients.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Launcher so `npx @octocodeai/freellama` works: finds the compiled Rust binary and hands the process to it.
|
|
3
|
+
//
|
|
4
|
+
// The binary is platform-specific and compiled by Cargo, so it is shipped in the tarball rather
|
|
5
|
+
// than built on install — an install-time `cargo build` would need a Rust toolchain on every
|
|
6
|
+
// consumer's machine. On a platform with no shipped binary the error names what it looked for and
|
|
7
|
+
// how to build one, instead of a bare ENOENT from deep inside a spawn.
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
|
|
15
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
16
|
+
const exe = process.platform === "win32" ? "freellama.exe" : "freellama";
|
|
17
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
18
|
+
const PLATFORM_SUFFIXES = process.platform === "linux"
|
|
19
|
+
? (process.report?.getReport()?.header?.glibcVersionRuntime ? ["-gnu", "-musl"] : ["-musl", "-gnu"])
|
|
20
|
+
: process.platform === "win32" ? ["-msvc"] : [""];
|
|
21
|
+
const platformIds = [...new Set(PLATFORM_SUFFIXES.map((suffix) => `${process.platform}-${process.arch}${suffix}`))];
|
|
22
|
+
const candidates = [
|
|
23
|
+
path.join(root, "..", "..", "target", "release", exe), // in-repo dev, no packing needed
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
for (const id of platformIds) {
|
|
27
|
+
try {
|
|
28
|
+
candidates.push(path.join(path.dirname(requireFromHere.resolve(`@octocodeai/freellama-native-${id}/package.json`)), exe));
|
|
29
|
+
} catch {
|
|
30
|
+
// Optional packages for other platforms are intentionally absent after install.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const binary = candidates.find((p) => existsSync(p));
|
|
35
|
+
if (!binary) {
|
|
36
|
+
console.error(
|
|
37
|
+
`freellama: no binary for ${process.platform}-${process.arch}.\n` +
|
|
38
|
+
`Looked in:\n${candidates.map((c) => ` ${c}`).join("\n")}\n` +
|
|
39
|
+
"Build it from a checkout with:\n cargo build --release\n" +
|
|
40
|
+
"Reinstall without --omit=optional. From a source checkout, run `cargo build --release`.",
|
|
41
|
+
);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Pass through stdio and the exit code: this is a launcher, not a wrapper that reinterprets output.
|
|
46
|
+
const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
47
|
+
|
|
48
|
+
// Forward termination to the child. Without this, a supervisor (or `kill`) that signals the npx
|
|
49
|
+
// process by PID kills only this launcher, and `freellama serve` is orphaned still holding its
|
|
50
|
+
// listener — the next start then fails with "address already in use" and nothing explains why.
|
|
51
|
+
// Ctrl-C already reaches both via the process group; this covers the targeted-signal case.
|
|
52
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) {
|
|
53
|
+
process.on(signal, () => {
|
|
54
|
+
if (!child.killed) child.kill(signal);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Reproduce the shell's own convention for a signalled child (128 + signal number) so callers can
|
|
59
|
+
// tell "interrupted" from "failed"; both used to collapse into a bare 1.
|
|
60
|
+
child.on("exit", (code, signal) => {
|
|
61
|
+
if (signal) {
|
|
62
|
+
process.exit(128 + (os.constants.signals[signal] ?? 15));
|
|
63
|
+
}
|
|
64
|
+
process.exit(code ?? 0);
|
|
65
|
+
});
|
|
66
|
+
child.on("error", (err) => {
|
|
67
|
+
console.error(`freellama: failed to start ${binary}: ${err.message}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octocodeai/freellama",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local Ollama model gateway, router, and benchmarker — CLI. Wraps the compiled Rust binary from packages/rust-core.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/bgauryy/FreeLlama.git",
|
|
8
|
+
"directory": "packages/cli"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/bgauryy/FreeLlama#readme",
|
|
11
|
+
"bugs": "https://github.com/bgauryy/FreeLlama/issues",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ollama",
|
|
14
|
+
"local-llm",
|
|
15
|
+
"gateway",
|
|
16
|
+
"coding-agent"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": "bin/freellama.mjs",
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "node -e \"process.stdout.write('freellama CLI launcher ready\\n')\"",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"test:watch": "vitest"
|
|
32
|
+
},
|
|
33
|
+
"license": "Apache-2.0 OR MIT",
|
|
34
|
+
"optionalDependencies": {
|
|
35
|
+
"@octocodeai/freellama-native-darwin-arm64": "0.1.0",
|
|
36
|
+
"@octocodeai/freellama-native-darwin-x64": "0.1.0",
|
|
37
|
+
"@octocodeai/freellama-native-linux-arm64-gnu": "0.1.0",
|
|
38
|
+
"@octocodeai/freellama-native-linux-arm64-musl": "0.1.0",
|
|
39
|
+
"@octocodeai/freellama-native-linux-x64-gnu": "0.1.0",
|
|
40
|
+
"@octocodeai/freellama-native-linux-x64-musl": "0.1.0",
|
|
41
|
+
"@octocodeai/freellama-native-win32-arm64-msvc": "0.1.0",
|
|
42
|
+
"@octocodeai/freellama-native-win32-x64-msvc": "0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/node": "^22.10.0",
|
|
50
|
+
"typescript": "^5.7.2",
|
|
51
|
+
"vitest": "^4.1.11"
|
|
52
|
+
}
|
|
53
|
+
}
|