ai-agentmanager 1.54.0 → 1.55.1
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/CHANGELOG.md +17 -0
- package/README.md +23 -0
- package/bin/acp-client.js +4 -1
- package/bin/local-run.js +90 -0
- package/package.json +1 -1
- package/public/app.js +28 -0
- package/public/index.html +5 -0
- package/public/style.css +2 -0
- package/public/system.js +21 -0
- package/src/cli.js +35 -2
- package/src/config.js +3 -0
- package/src/engines/codex.js +3 -3
- package/src/engines/index.js +18 -3
- package/src/engines/local.js +156 -0
- package/src/git.js +4 -2
- package/src/localmodels.js +260 -0
- package/src/manager.js +12 -3
- package/src/server.js +25 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.55.1 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
From running a real task on `gpt-oss:20b` (Ollama) through each harness.
|
|
6
|
+
|
|
7
|
+
- **Local models: OpenCode is now the default harness.** `--engine local` picks OpenCode when it is installed, then Codex, then Claude Code. This changes what you get if you have OpenCode installed and relied on the default: it was Codex in 1.55.0. To keep Codex, run `agentmgr models --harness codex`. The reason: the model finished the same task on OpenCode in 5 of 6 runs and on Codex in about 5 of 14.
|
|
8
|
+
- **Local · Codex no longer asks before every command.** Open models asked to leave the sandbox even for `ls` and `cat`, nine prompts for a four-line fix. The model is now told its commands need no approval.
|
|
9
|
+
- **Known, not fixed:** with `gpt-oss:20b` on Ollama, Codex's file edits often fail (the model writes a tool call Ollama can't read, and the turn stops). Use OpenCode or Claude Code for that model.
|
|
10
|
+
- **ACP agents (OpenCode and others):** a permission menu that named only a folder ("Permission needed: /etc") now names the tool first ("read /etc").
|
|
11
|
+
|
|
12
|
+
## 1.55.0 (2026-11-16)
|
|
13
|
+
|
|
14
|
+
- **Local models.** Agents can run on a model served from this computer: Ollama, LM Studio, llama.cpp or MLX. The app finds the servers on their usual ports and lists their models in **OS** and with `agentmgr models`, with a note on which an agent can use; a model that can't call tools is not offered. An agent's model names the server, say `ollama/qwen3-coder:30b`.
|
|
15
|
+
- **Three harnesses to choose from**, each an engine: **Local · Codex** (`local-codex`), **Local · OpenCode** (`local-opencode`) and **Local · Claude Code** (`local-claude`; Anthropic doesn't support Claude Code on other models, and the server has to speak Anthropic's API, which Ollama does). Each needs its own CLI installed. Sessions, resume and the inbox work as with the harness's own engine; nothing is costed, and summaries and reviews stay with your usual engine.
|
|
16
|
+
- **Room for an agent's context.** Ollama starts a model with a few thousand tokens of context, too little for an agent, so the app makes a copy of the model with more (32k by default; `agentmgr models --context`). Codex runs local models from a home of its own without your plugins and MCP servers, and Claude Code leaves MCP servers out, since those would fill a small context before the task starts. Your Codex sessions folder and AGENTS.md are still used.
|
|
17
|
+
- **Settings:** `agentmgr models --add name=address`, `--remove`, `--default`, `--harness`, `--on`, `--off`. Tried so far with a small model on Ollama only: a capable model (20 GB or more of memory) is what a real task needs.
|
|
18
|
+
- **Git:** the app's background `git status` no longer takes the index lock, which could make an agent's own `git add` or `git commit` fail with "index.lock: File exists" now and then.
|
|
19
|
+
|
|
3
20
|
## 1.54.0 (2026-11-15)
|
|
4
21
|
|
|
5
22
|
- **Repeat runs: flaky or broken.** One test run can pass or fail by chance, so the app's own test runs (the Eval's, and a race's) can be repeated on the same code. By default a run that passes is believed and a run that fails is run once more, which tells a flaky test from a broken one. **Runs** (1 to 5) beside the test command, in the Eval (kept for the project) or in a race (`agentmgr race test <race> --runs 3`), makes that many runs every time. Passed in some runs and failed in others is **flaky**: in the Eval it counts for part of the tests' weight, is listed as pending and keeps confidence under 100%, so nothing merges on it automatically; in a race the attempt shows `≈ flaky 2/3`. A failing test command now takes twice as long, since it is run again.
|
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ Run one background [Claude Code](https://claude.com/claude-code) agent per inten
|
|
|
36
36
|
- **Skills.** **Skills…** in the menu (or `agentmgr skills`) lists the Agent Skills Claude Code has here, yours and each project's, with which agents used them. Add more from a git repository (`anthropics/skills`, or any https address): you see what it offers first, with each skill's scripts flagged, then pick. A skill added here remembers its repository and commit, so **Check** says when a newer version is there and **Update** brings it; one you edited says so.
|
|
37
37
|
- **Board.** **Board** in the top bar (or `B`, `#board`): every agent as a card in the column for where its work stands: starting, working, needs you, waiting, in review, done, closed. Cards move by themselves; drag one onto **Closed** to close its session, or from Closed onto **Waiting** to resume it.
|
|
38
38
|
- **Lanes.** Every agent gets a range of ports and a name ending no other agent has, in its environment and its instructions, so dev servers and test databases of agents working side by side don't collide. **OS** shows what each open session listens on (`agentmgr lanes`).
|
|
39
|
+
- **Local models.** Models served on this computer by Ollama, LM Studio, llama.cpp or MLX are found by themselves, and an agent can run on one, with the Codex CLI, OpenCode or Claude Code as the harness: no plan, no limits, nothing leaves the machine (`agentmgr models`).
|
|
39
40
|
- **Lean output.** A switch in **Usage** (off by default; `agentmgr usage --lean on`): long command output (test runs, installs, builds) is trimmed before the agent reads it, so a plan's limits last longer. Colours and progress redraws go, runs of near-identical lines are folded, and of a long middle only the lines that look like errors or warnings stay; the start and end are kept, and the whole output is saved to a file the agent can read. Claude Code only, for sessions started after you switch it on. Usage shows how much was trimmed.
|
|
40
41
|
- **Runbooks for support.** A runbook for the support team written from a release ticket, every ticket of an epic, or a project's code changes in a time frame: what changed, what customers may see, how to check it, troubleshooting, rollback, when to escalate, and what to confirm with engineering.
|
|
41
42
|
- **Decide.** Help with the decisions, not only the tasks: a plan to review or an agent's question arrives with its options, the one recommended, why, and the risk; calls you keep making become standing decisions that are handled for you and reported; the backlog is ranked by impact; a date at risk is laid out as choices; and past decisions are looked back on.
|
|
@@ -203,6 +204,7 @@ agentmgr debt <project> --scan # the tech debt radar: files that
|
|
|
203
204
|
agentmgr audit <agent> --start # security audit in its session (a scope in words, --fix "1 and 3"; no arguments: the report)
|
|
204
205
|
agentmgr skills # Claude Code's skills here (look <repo>, add <repo> <names...>, check|update|rm <id>)
|
|
205
206
|
agentmgr lanes # every agent's own ports and name ending (--off, --port off, --base, --size)
|
|
207
|
+
agentmgr models # models served on this computer (Ollama, LM Studio, llama.cpp, MLX), for --engine local
|
|
206
208
|
agentmgr usage # each engine's plan limits: used, left, resets (--now, --lean on, --warn 80, --hold 95, --default codex)
|
|
207
209
|
agentmgr runbook --ticket REL-42 # a support runbook from a release ticket (or --epic KEY, or --since 2026-10-01 -p <project>; -o file.md)
|
|
208
210
|
agentmgr decide # what waits for your decision, with its recommendation (--do <n>, --handled, --standing, --autonomy p=level, --priority, --risk)
|
|
@@ -852,6 +854,27 @@ Google's **Antigravity CLI** (`agy`, signed in with your Google account) works t
|
|
|
852
854
|
|
|
853
855
|
Meta's **Muse Code** (`muse`, installed with `curl -fsSL https://dev.meta.ai/install.sh | bash` and signed in with `muse login`) works the same way: `--engine muse`. AI Agent Manager adopts the session Muse starts, resumes it with `muse resume` (a message for a resumed session is typed once Muse is idle), trusts the agent's folder for each run with `--trust-workspace` instead of saving it, reads the conversation and token usage from Muse's session log, shows its trust and approval questions in the inbox, stops it cleanly with SIGTERM, and runs Explain with `muse exec` in the read-only profile. Commands and edits aren't read from its log yet, so stuck detection has less to go on for Muse agents. When Muse runs in contributor mode (an account without a plan), the engine picker says so: Meta may use your code and conversations to improve its products. `engines.muse.bin` points at another binary, and `engines.muse.args` adds arguments to every run.
|
|
854
856
|
|
|
857
|
+
## Local models: Ollama, LM Studio, llama.cpp, MLX
|
|
858
|
+
|
|
859
|
+
An agent can run on a model served on this computer instead of a provider's: no plan, no limits, and nothing leaves the machine. AI Agent Manager finds the model servers running here by asking their usual addresses, and runs the model in a harness you choose, pointed at the local server:
|
|
860
|
+
|
|
861
|
+
| Harness | Engine | Notes |
|
|
862
|
+
|---|---|---|
|
|
863
|
+
| **Codex CLI** (open source; `npm i -g @openai/codex`, no sign-in needed for this) | `local-codex` | A small first message, so it suits small contexts. It is told that its commands need no approval, since open models otherwise ask at every step. With `gpt-oss:20b` on Ollama its file edits often fail (the model writes a tool call Ollama can't read, and the turn stops): use OpenCode or Claude Code for that model. |
|
|
864
|
+
| **OpenCode** (open source; `npm i -g opencode-ai`) | `local-opencode` | The default: in our trials an open model finished a task on it more often than on Codex. Made for many providers. Runs over ACP, so the app reads less from it (no token counts). |
|
|
865
|
+
| **Claude Code** | `local-claude` | Everything the app does for Claude Code agents, but Anthropic doesn't support Claude Code on other models: expect rough edges. The server has to speak Anthropic's API, which Ollama does. |
|
|
866
|
+
|
|
867
|
+
`--engine local` is the harness set with `agentmgr models --harness codex|opencode|claude`, or else the first installed of OpenCode, Codex and Claude Code.
|
|
868
|
+
|
|
869
|
+
- **What is found.** Ollama (port 11434), LM Studio (1234), and llama.cpp's `llama-server` or MLX's `mlx_lm.server` (8080), plus any server that speaks the OpenAI API at an address you add: `agentmgr models --add mlx=http://127.0.0.1:8081`. **OS** lists each server's models with their size and whether an agent can use them, as does `agentmgr models`. A model that can't call tools is listed but can't be chosen: an agent needs tools to read and change files. Embedding models are left out.
|
|
870
|
+
- **Starting an agent on one.** Choose **Local · Codex**, **Local · OpenCode** or **Local · Claude Code** as the engine in New agent or Ask Agent (each offered while its harness is installed and a server with a usable model is running) and pick the model, or `agentmgr add --engine local --model ollama/qwen3-coder:30b "…"`. A model is written `<server>/<model>`. `agentmgr models --default <model>` sets the one used when none is given.
|
|
871
|
+
- **Everything else is the harness's own engine**: worktrees and lanes, the brief, the inbox with the harness's approval menus, stuck detection, stop and resume. Summaries and reviews (Explain, Review with AI) stay with your usual engine, no cost is counted, and the Usage window leaves local engines out: there is no plan to show. Claude Code is started without MCP servers, whose tool lists would take much of a local model's context. Not in containers yet.
|
|
872
|
+
- **Context on Ollama.** Ollama starts a model with a few thousand tokens of context whatever the model can take, which is less than a coding agent's first message. So the first time an agent starts on an Ollama model, a copy of it with room for 32,768 tokens is made (`gpt-oss:20b` becomes `gpt-oss-am32k:20b` in `ollama list`; the weights are shared, so it takes no disk space). `agentmgr models --context <tokens>` changes the room, and `--context 0` leaves Ollama's own setting alone. Other servers keep the context they were started with: give LM Studio, llama.cpp or MLX at least 16,000 tokens.
|
|
873
|
+
- **A Codex home of its own.** Local Codex agents run Codex from `~/.agentmanager/codex-local`, not your `~/.codex`: your Codex plugins and MCP servers would fill a local model's context before the task starts. Your `AGENTS.md` is still used, and sessions are kept with your other Codex sessions.
|
|
874
|
+
- **What to expect.** A local model is much weaker than Claude or GPT at work of many steps, and slower. On a Mac with 24 GB of memory, a model of about 20 billion parameters is the practical ceiling, one agent at a time. Small models (under 7 billion parameters) are marked: they answer a question but rarely finish a task.
|
|
875
|
+
|
|
876
|
+
`"localModels": { "enabled": false }` in config.json (or `agentmgr models --off`) stops the lookups. `agentmgr models --remove <name>` stops asking one server.
|
|
877
|
+
|
|
855
878
|
## Agents in containers
|
|
856
879
|
|
|
857
880
|
For isolation, an agent can run in its own Docker container: it sees only its own folder (mounted at the same path), its repository's git data, its brief and its uploads, and nothing else on the computer. Everything else works as usual: sessions, resume, tracking and usage, the inbox, **Open shell** (which opens inside the container), stop and restart.
|
package/bin/acp-client.js
CHANGED
|
@@ -208,7 +208,10 @@ async function handle(method, p) {
|
|
|
208
208
|
let answer = null; // resolves with the next line typed while a permission menu is open
|
|
209
209
|
async function permission(p) {
|
|
210
210
|
const options = p.options ?? [];
|
|
211
|
-
|
|
211
|
+
// Some agents name only what the tool wants (a folder outside the project, say): put the tool's own name first.
|
|
212
|
+
const tool = tools.get(p.toolCall?.toolCallId)?.title;
|
|
213
|
+
const what = p.toolCall?.title ?? tool ?? 'a tool';
|
|
214
|
+
const title = tool && tool !== 'tool' && !what.toLowerCase().includes(tool.toLowerCase()) ? `${tool} ${what}` : what;
|
|
212
215
|
const pick = (kinds) => options.find((o) => kinds.includes(o.kind));
|
|
213
216
|
if (yes || deny || once) {
|
|
214
217
|
const o = deny || once ? pick(['reject_once', 'reject_always']) : pick(['allow_once', 'allow_always']);
|
package/bin/local-run.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Starts a harness (the Codex CLI, Claude Code or OpenCode) on a model served on this computer
|
|
3
|
+
// (engines/local.js):
|
|
4
|
+
// local-run.js --harness <codex|claude|opencode> --url <server> --model <name> --context <tokens> -- <command> [arguments]
|
|
5
|
+
// It checks that the server answers and has the model, and tells the harness to talk to it. Ollama
|
|
6
|
+
// starts a model with little context whatever the model can take, so for Ollama it first makes a
|
|
7
|
+
// copy of the model with room for an agent (a few lines in Ollama's list; the weights are shared).
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import { variantName } from '../src/localmodels.js';
|
|
10
|
+
|
|
11
|
+
const argv = process.argv.slice(2);
|
|
12
|
+
const split = argv.indexOf('--');
|
|
13
|
+
const opt = {};
|
|
14
|
+
for (let i = 0; i < split; i += 2) opt[argv[i].replace(/^--/, '')] = argv[i + 1];
|
|
15
|
+
const [bin, ...rest] = argv.slice(split + 1);
|
|
16
|
+
const url = String(opt.url ?? '').replace(/\/+$/, '');
|
|
17
|
+
const context = Number(opt.context) || 0;
|
|
18
|
+
|
|
19
|
+
const say = (m) => process.stderr.write(`\x1b[2m[agentmgr] ${m}\x1b[0m\r\n`);
|
|
20
|
+
const stop = (m) => {
|
|
21
|
+
process.stderr.write(`[agentmgr] ${m}\r\n`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
};
|
|
24
|
+
async function call(path, body, timeoutMs = 5000) {
|
|
25
|
+
try {
|
|
26
|
+
const res = await fetch(`${url}${path}`, { signal: AbortSignal.timeout(timeoutMs), ...(body ? { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}) });
|
|
27
|
+
const text = await res.text();
|
|
28
|
+
let json = null;
|
|
29
|
+
try {
|
|
30
|
+
json = JSON.parse(text);
|
|
31
|
+
} catch {}
|
|
32
|
+
return { ok: res.ok, json, text };
|
|
33
|
+
} catch (err) {
|
|
34
|
+
return { ok: false, json: null, text: err.message };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (split < 0 || !bin || !url || !opt.model) stop('local-run: --url, --model and a command after "--" are needed');
|
|
39
|
+
|
|
40
|
+
let model = opt.model;
|
|
41
|
+
let window = null;
|
|
42
|
+
const tags = await call('/api/tags');
|
|
43
|
+
if (Array.isArray(tags.json?.models)) {
|
|
44
|
+
// Ollama.
|
|
45
|
+
const mine = tags.json.models.find((m) => m.name === model || m.name === `${model}:latest`);
|
|
46
|
+
if (!mine) stop(`Ollama has no model "${model}". Get it with: ollama pull ${model}`);
|
|
47
|
+
if (context > 0) {
|
|
48
|
+
const most = Number(mine.details?.context_length) || context;
|
|
49
|
+
window = Math.min(context, most);
|
|
50
|
+
const copy = variantName(model, window);
|
|
51
|
+
if (!tags.json.models.some((m) => m.name === copy)) {
|
|
52
|
+
say(`Giving ${model} room for ${window} tokens (as ${copy})…`);
|
|
53
|
+
const made = await call('/api/create', { model: copy, from: mine.name, parameters: { num_ctx: window }, stream: false }, 60_000);
|
|
54
|
+
if (!made.ok || made.json?.error) stop(`Ollama couldn't make ${copy}: ${made.json?.error ?? made.text}`);
|
|
55
|
+
}
|
|
56
|
+
model = copy;
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
const list = await call('/v1/models');
|
|
60
|
+
if (!Array.isArray(list.json?.data)) stop(`No model server answers at ${url}. Start it, then start this agent again.`);
|
|
61
|
+
// llama.cpp says how much context it was started with.
|
|
62
|
+
window = Number((await call('/props')).json?.default_generation_settings?.n_ctx) || null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const env = { ...process.env };
|
|
66
|
+
let args = rest;
|
|
67
|
+
if (opt.harness === 'claude') {
|
|
68
|
+
// Claude Code, talking to the server's Anthropic-style API; every role it has a model for gets this one
|
|
69
|
+
// (named in its environment: its command may be more than one word, so no argument is added here).
|
|
70
|
+
Object.assign(env, { ANTHROPIC_BASE_URL: url, ANTHROPIC_MODEL: model, ANTHROPIC_AUTH_TOKEN: 'local', ANTHROPIC_API_KEY: '', ANTHROPIC_SMALL_FAST_MODEL: model, ANTHROPIC_DEFAULT_HAIKU_MODEL: model, ANTHROPIC_DEFAULT_SONNET_MODEL: model, ANTHROPIC_DEFAULT_OPUS_MODEL: model, CLAUDE_CODE_SUBAGENT_MODEL: model, CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: '1' });
|
|
71
|
+
delete env.CLAUDE_CODE_OAUTH_TOKEN;
|
|
72
|
+
// It takes the context for a Claude model's 200,000 tokens: summarize before this one's is full.
|
|
73
|
+
if (window) env.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE = String(Math.max(1, Math.min(90, Math.floor((window * 0.75 * 100) / 200_000))));
|
|
74
|
+
} else if (opt.harness === 'opencode') {
|
|
75
|
+
// OpenCode, given the server as a provider of its own for this run.
|
|
76
|
+
const limit = window ? { limit: { context: window, output: Math.min(8192, Math.floor(window / 4)) } } : {};
|
|
77
|
+
env.OPENCODE_CONFIG_CONTENT = JSON.stringify({ $schema: 'https://opencode.ai/config.json', provider: { agentmgr: { npm: '@ai-sdk/openai-compatible', name: 'Local', options: { baseURL: `${url}/v1` }, models: { [model]: { name: opt.model, ...limit } } } }, model: `agentmgr/${model}`, small_model: `agentmgr/${model}` });
|
|
78
|
+
} else {
|
|
79
|
+
// Codex, with the server as its model provider. It takes options after `resume`.
|
|
80
|
+
// Open models tend to give every command a `justification`, Codex answers that one needs
|
|
81
|
+
// `sandbox_permissions`, and the model then asks to leave the sandbox for `ls` and `cat`: a
|
|
82
|
+
// prompt for you at every step. Told this, they mostly stop.
|
|
83
|
+
const quiet = 'Shell commands already run in a sandbox that can read every file and write in the project, so they need no approval. When you call exec_command, give `cmd` and leave out `justification` and `sandbox_permissions`. Only if a command has failed because the sandbox blocked it (network access, or writing outside the project), repeat it with `sandbox_permissions` set to "require_escalated" and a `justification`.';
|
|
84
|
+
const flags = ['-c', `model_providers.agentmgr={name="Local",base_url="${url}/v1"}`, '-c', 'model_provider="agentmgr"', ...(window ? ['-c', `model_context_window=${window}`] : []), '-c', `developer_instructions=${JSON.stringify(quiet)}`, '--model', model];
|
|
85
|
+
args = rest[0] === 'resume' ? ['resume', ...flags, ...rest.slice(1)] : [...flags, ...rest];
|
|
86
|
+
}
|
|
87
|
+
const child = spawn(bin, args, { stdio: 'inherit', env });
|
|
88
|
+
for (const sig of ['SIGHUP', 'SIGINT', 'SIGTERM']) process.on(sig, () => child.kill(sig));
|
|
89
|
+
child.on('error', (err) => stop(`Couldn't start ${bin}: ${err.message}`));
|
|
90
|
+
child.on('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -4450,6 +4450,7 @@ $('#ask-form').addEventListener('submit', async (e) => {
|
|
|
4450
4450
|
question: String(f.get('question') || '').trim() || undefined,
|
|
4451
4451
|
name: String(f.get('name') || '').trim() || undefined,
|
|
4452
4452
|
engine: f.get('engine') || undefined,
|
|
4453
|
+
model: (String(f.get('engine') || '').startsWith('local-') && String(f.get('model') || '').trim()) || undefined,
|
|
4453
4454
|
attachments: askFiles.paths().length ? askFiles.paths() : undefined,
|
|
4454
4455
|
});
|
|
4455
4456
|
agents.set(a.id, a);
|
|
@@ -5190,10 +5191,37 @@ async function loadEngines() {
|
|
|
5190
5191
|
};
|
|
5191
5192
|
sel.addEventListener('change', show);
|
|
5192
5193
|
show();
|
|
5194
|
+
sel.addEventListener('change', () => syncLocalModel(sel.form));
|
|
5193
5195
|
}
|
|
5194
5196
|
} catch {}
|
|
5195
5197
|
}
|
|
5196
5198
|
|
|
5199
|
+
/**
|
|
5200
|
+
* A local engine (Codex, OpenCode or Claude Code as the harness) takes a model served on this computer ("ollama/qwen3-coder:30b"): the
|
|
5201
|
+
* form's model field then offers the ones found, and starts on the default or the first.
|
|
5202
|
+
*/
|
|
5203
|
+
async function syncLocalModel(form) {
|
|
5204
|
+
const input = form.model;
|
|
5205
|
+
if (!input) return;
|
|
5206
|
+
const local = form.engine.value.startsWith('local-');
|
|
5207
|
+
const field = form.id === 'ask-form' ? $('#ask-model-field') : null;
|
|
5208
|
+
if (field) field.hidden = !local;
|
|
5209
|
+
if (!local) {
|
|
5210
|
+
if (input.dataset.placeholder !== undefined) input.placeholder = input.dataset.placeholder;
|
|
5211
|
+
input.removeAttribute('list');
|
|
5212
|
+
if (input.dataset.local === input.value) input.value = '';
|
|
5213
|
+
return;
|
|
5214
|
+
}
|
|
5215
|
+
input.dataset.placeholder ??= input.placeholder;
|
|
5216
|
+
input.setAttribute('list', 'local-models-list');
|
|
5217
|
+
input.placeholder = '<server>/<model>';
|
|
5218
|
+
const v = await api('GET', '/local-models').catch(() => null);
|
|
5219
|
+
const models = (v?.servers ?? []).flatMap((s) => s.models.filter((m) => m.usable).map((m) => ({ ...m, server: s.label })));
|
|
5220
|
+
$('#local-models-list').replaceChildren(...models.map((m) => Object.assign(document.createElement('option'), { value: m.id, label: [m.server, m.sizeBytes ? `${(m.sizeBytes / 1024 ** 3).toFixed(1)} GB` : '', m.params, ...m.notes].filter(Boolean).join(' · ') })));
|
|
5221
|
+
if (!form.engine.value.startsWith('local-')) return;
|
|
5222
|
+
if (!input.value.includes('/')) input.value = input.dataset.local = (v?.default && models.some((m) => m.id === v.default) ? v.default : models[0]?.id) ?? '';
|
|
5223
|
+
}
|
|
5224
|
+
|
|
5197
5225
|
async function boot() {
|
|
5198
5226
|
if (REMOTE) {
|
|
5199
5227
|
document.body.classList.add('remote');
|
package/public/index.html
CHANGED
|
@@ -450,6 +450,7 @@
|
|
|
450
450
|
<dialog id="standup-dialog" class="standup-dialog" aria-label="Standup">
|
|
451
451
|
<div id="standup-body"></div>
|
|
452
452
|
</dialog>
|
|
453
|
+
<datalist id="local-models-list"></datalist>
|
|
453
454
|
<dialog id="ask-dialog">
|
|
454
455
|
<form id="ask-form" method="dialog">
|
|
455
456
|
<h2>Ask an agent</h2>
|
|
@@ -469,6 +470,10 @@
|
|
|
469
470
|
<select name="engine"><option value="">Claude Code</option></select>
|
|
470
471
|
<span class="hint warn" id="ask-engine-notice" hidden></span>
|
|
471
472
|
</label>
|
|
473
|
+
<label id="ask-model-field" hidden>
|
|
474
|
+
Model
|
|
475
|
+
<input name="model" list="local-models-list" />
|
|
476
|
+
</label>
|
|
472
477
|
</div>
|
|
473
478
|
<p id="ask-error" class="error" hidden></p>
|
|
474
479
|
<div class="dialog-actions">
|
package/public/style.css
CHANGED
|
@@ -1784,3 +1784,5 @@ table.eval-items tr.eval-na td { color: var(--muted); }
|
|
|
1784
1784
|
@media (max-width: 720px) {
|
|
1785
1785
|
.board-cols { grid-auto-columns: minmax(220px, 80%); }
|
|
1786
1786
|
}
|
|
1787
|
+
.os-local td:first-child { white-space: normal; overflow-wrap: anywhere; }
|
|
1788
|
+
.os-local-no code { opacity: 0.6; }
|
package/public/system.js
CHANGED
|
@@ -18,12 +18,15 @@ export function initSystem({ api, $, esc, toast, openAgent, openPort }) {
|
|
|
18
18
|
const body = $('#os-body');
|
|
19
19
|
let data = null;
|
|
20
20
|
let problem = null;
|
|
21
|
+
let local = null;
|
|
21
22
|
let timer = null;
|
|
22
23
|
|
|
23
24
|
async function load() {
|
|
24
25
|
try {
|
|
25
26
|
data = await api('GET', '/system');
|
|
26
27
|
problem = null;
|
|
28
|
+
// The model servers running here (asked again by the daemon every few seconds at most).
|
|
29
|
+
local = await api('GET', '/local-models').catch(() => local);
|
|
27
30
|
} catch (e) {
|
|
28
31
|
problem = e.message;
|
|
29
32
|
}
|
|
@@ -52,6 +55,23 @@ export function initSystem({ api, $, esc, toast, openAgent, openPort }) {
|
|
|
52
55
|
<polygon points="0,${h} ${xy.join(' ')} ${w},${h}"></polygon><polyline points="${xy.join(' ')}"></polyline></svg>`;
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
// A model named by its file (llama.cpp) is shown by the file's name; the whole of it is in the title.
|
|
59
|
+
const short = (id) => (id.length > 60 && id.includes('//') ? `${id.slice(0, id.indexOf('/'))}/…${id.slice(id.lastIndexOf('/'))}`.replace(/(.{28}).+(.{12})$/, '$1…$2') : id);
|
|
60
|
+
|
|
61
|
+
/** Models served on this computer, for agents on the "Local model" engine. */
|
|
62
|
+
function localHtml() {
|
|
63
|
+
const servers = (local?.servers ?? []).filter((s) => s.running);
|
|
64
|
+
if (!local?.enabled || !servers.length) return '';
|
|
65
|
+
const models = servers.flatMap((s) => s.models.map((m) => ({ ...m, server: s })));
|
|
66
|
+
const harnesses = (local.harnesses ?? []).filter((h) => h.installed);
|
|
67
|
+
return `<h3 title="Models served on this computer. Start an agent on one with a Local engine: the harness (Codex, OpenCode or Claude Code) is pointed at the server">Local models <span class="hint">${servers.map((s) => `${esc(s.label)}${s.version ? ` ${esc(s.version)}` : ''}`).join(', ')}${harnesses.length ? ` · run by ${harnesses.map((h) => esc(h.label)).join(', ')}` : ''}</span></h3>
|
|
68
|
+
${models.length
|
|
69
|
+
? `<table class="issues os-table os-local"><thead><tr><th>Model</th><th class="num">Size</th><th title="Whether an agent can work with it: it has to call tools to read and change files">For agents</th></tr></thead><tbody>
|
|
70
|
+
${models.map((m) => `<tr class="${m.usable ? '' : 'os-local-no'}"><td><code title="${esc(m.id)}">${esc(short(m.id))}</code>${m.loaded ? ' <span class="tag" title="In memory now">loaded</span>' : ''}${m.notes.length ? `<div class="hint">${esc(m.notes.join('. '))}</div>` : ''}</td><td class="num">${[m.sizeBytes ? bytes(m.sizeBytes) : '', esc(m.params ?? '')].filter(Boolean).join(' · ')}</td><td>${m.usable ? 'Yes' : '<span class="os-port-out">No</span>'}</td></tr>`).join('')}
|
|
71
|
+
</tbody></table>`
|
|
72
|
+
: '<p class="hint">No model yet.</p>'}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
const row = (k, v) => (v ? `<tr><th>${esc(k)}</th><td>${v}</td></tr>` : '');
|
|
56
76
|
|
|
57
77
|
function draw() {
|
|
@@ -120,6 +140,7 @@ export function initSystem({ api, $, esc, toast, openAgent, openPort }) {
|
|
|
120
140
|
</tbody></table>`
|
|
121
141
|
: '<p class="hint">No agent session is open.</p>'}
|
|
122
142
|
${lanes ? `<div class="os-lanes"><label title="Each agent gets a range of ports and a name ending no other agent has, in its environment (AGENT_PORTS, AGENT_SUFFIX) and its instructions, so dev servers and test databases of agents working side by side don't collide. For sessions started from now on"><input type="checkbox" data-os-lanes="enabled" ${lanes.enabled ? 'checked' : ''} /> A lane of ports for each agent</label>${lanes.enabled ? `<label title="Many dev servers listen on PORT when it is set. Turn off if your projects use PORT for something else"><input type="checkbox" data-os-lanes="port" ${lanes.port ? 'checked' : ''} /> Set PORT to its first port</label><span class="hint">${lanes.size} port${lanes.size === 1 ? '' : 's'} each, from ${lanes.base}</span>` : ''}</div>` : ''}
|
|
143
|
+
${localHtml()}
|
|
123
144
|
<h3>Busiest processes <span class="hint">of ${processes.count}</span></h3>
|
|
124
145
|
<table class="issues os-table"><thead><tr><th>Process</th><th class="num" title="Of one core: 200% is two cores busy">Processor</th><th class="num">Memory</th><th class="num">PID</th></tr></thead><tbody>
|
|
125
146
|
${processes.top.map((p) => `<tr><td title="${esc(p.command)}">${esc(p.name)}</td><td class="num">${p.cpu}%</td><td class="num">${bytes(p.mem)}</td><td class="num hint">${p.pid}</td></tr>`).join('')}
|
package/src/cli.js
CHANGED
|
@@ -344,7 +344,7 @@ export async function main(argv) {
|
|
|
344
344
|
]),
|
|
345
345
|
)
|
|
346
346
|
.option('-m, --model <model>', 'model (for the chosen engine)')
|
|
347
|
-
.option('-e, --engine <engine>', 'agent engine: claude (default), codex, antigravity or
|
|
347
|
+
.option('-e, --engine <engine>', 'agent engine: claude (default), codex, antigravity, muse, or local (local-codex, local-opencode, local-claude) with --model <server>/<model>: see agentmgr models')
|
|
348
348
|
.option('--file-attach <path>', 'attach a file to the request (a screenshot, a log); repeat for more', collect)
|
|
349
349
|
.option('--container', 'run each agent in its own Docker container (see agentmgr sandbox)')
|
|
350
350
|
.option('--no-container', 'run on this computer even if containers are the default')
|
|
@@ -434,7 +434,7 @@ export async function main(argv) {
|
|
|
434
434
|
.argument('[question...]', 'optional first question')
|
|
435
435
|
.option('-n, --name <name>', 'display name')
|
|
436
436
|
.option('-m, --model <model>', 'model (for the chosen engine)')
|
|
437
|
-
.option('-e, --engine <engine>', 'agent engine: claude (default), codex, antigravity or
|
|
437
|
+
.option('-e, --engine <engine>', 'agent engine: claude (default), codex, antigravity, muse, or local (local-codex, local-opencode, local-claude) with --model <server>/<model>: see agentmgr models')
|
|
438
438
|
.option('--file-attach <path>', 'attach a file to the question (a screenshot, a log); repeat for more', collect)
|
|
439
439
|
.option('--no-attach', 'start it in the background only')
|
|
440
440
|
.action(async (words, opts) => {
|
|
@@ -869,6 +869,39 @@ export async function main(argv) {
|
|
|
869
869
|
throw new Error(`Unknown action ${action} (ls, show, look, add, check, update, rm)`);
|
|
870
870
|
});
|
|
871
871
|
|
|
872
|
+
program
|
|
873
|
+
.command('models')
|
|
874
|
+
.description('Models running on this computer (Ollama, LM Studio, llama.cpp, MLX), for agents on a local engine (Codex, OpenCode or Claude Code as the harness): --engine local --model <server>/<model>')
|
|
875
|
+
.option('--add <name=address>', 'also ask a server at this address, say mlx=http://127.0.0.1:8081')
|
|
876
|
+
.option('--remove <name>', 'stop asking a server')
|
|
877
|
+
.option('--context <tokens>', "the room Ollama gives a model for an agent (0: leave Ollama's own)")
|
|
878
|
+
.option('--default <model>', 'the model of a local agent started without one')
|
|
879
|
+
.option('--harness <name>', 'what runs the model when the engine is just "local": codex, opencode or claude')
|
|
880
|
+
.option('--on', 'look for local models')
|
|
881
|
+
.option('--off', 'stop looking')
|
|
882
|
+
.option('--json', 'print JSON')
|
|
883
|
+
.action(async (opts) => {
|
|
884
|
+
await daemon();
|
|
885
|
+
const patch = { ...(opts.on ? { enabled: true } : opts.off ? { enabled: false } : {}), ...(opts.context !== undefined ? { context: opts.context } : {}), ...(opts.default !== undefined ? { default: opts.default } : {}), ...(opts.harness !== undefined ? { harness: opts.harness } : {}), ...(opts.remove ? { remove: opts.remove } : {}) };
|
|
886
|
+
if (opts.add) {
|
|
887
|
+
const at = opts.add.indexOf('=');
|
|
888
|
+
if (at < 1) throw new Error('--add takes <name>=<address>, say mlx=http://127.0.0.1:8081');
|
|
889
|
+
patch.add = { name: opts.add.slice(0, at), url: opts.add.slice(at + 1) };
|
|
890
|
+
}
|
|
891
|
+
const v = Object.keys(patch).length ? await api('PUT', '/local-models/settings', patch) : await api('GET', '/local-models?fresh=1');
|
|
892
|
+
if (opts.json) return console.log(JSON.stringify(v, null, 2));
|
|
893
|
+
if (!v.enabled) return console.log(`Local models ${dim('off')} ${dim('(agentmgr models --on)')}`);
|
|
894
|
+
const gb = (n) => (n ? `${(n / 1024 ** 3).toFixed(1)} GB` : '');
|
|
895
|
+
if (!v.servers.some((s) => s.running)) console.log(dim('No local model server is running here (Ollama, LM Studio, llama.cpp or MLX at their usual addresses).'));
|
|
896
|
+
for (const s of v.servers) {
|
|
897
|
+
console.log(`${s.label}${s.version ? dim(` ${s.version}`) : ''} ${dim(s.url)}${s.running ? '' : dim(' · not running')}`);
|
|
898
|
+
for (const m of s.models) console.log(` ${m.usable ? green('✓') : dim('✗')} ${m.id.padEnd(36)} ${[gb(m.sizeBytes), m.params, m.loaded ? 'in memory' : ''].filter(Boolean).join(' · ')}${m.notes.length ? dim(` ${m.notes.join('; ')}`) : ''}`);
|
|
899
|
+
if (s.running && !s.models.length) console.log(dim(' No model yet.'));
|
|
900
|
+
}
|
|
901
|
+
console.log(`Harnesses: ${v.harnesses.map((h) => (h.installed ? `${h.id === v.harness ? green(`${h.label} (--engine local)`) : h.label} ${dim(`--engine ${h.engine}`)}` : dim(`${h.label} not installed`))).join(' · ')}`);
|
|
902
|
+
console.log(dim(`Start an agent on one: agentmgr add "<task>" --engine local --model <server>/<model>${v.context ? ` · Ollama models get ${v.context} tokens of context` : ''}${v.default ? ` · default ${v.default}` : ''}`));
|
|
903
|
+
});
|
|
904
|
+
|
|
872
905
|
program
|
|
873
906
|
.command('lanes')
|
|
874
907
|
.description("Every agent's own ports and name ending, so dev servers and test databases of agents working side by side don't collide")
|
package/src/config.js
CHANGED
|
@@ -82,6 +82,9 @@ const DEFAULTS = {
|
|
|
82
82
|
calendar: { ics: [], workStart: '09:00', workEnd: '18:00' },
|
|
83
83
|
// Lanes: every agent's own range of ports and name ending; `port` also sets PORT to its first port (lanes.js).
|
|
84
84
|
lanes: { enabled: true, base: 21000, size: 10, port: true },
|
|
85
|
+
// Local models: servers on this computer (Ollama, LM Studio, llama.cpp, MLX) and their models, for the
|
|
86
|
+
// "Local model" engine; `context` is the room Ollama gives a model for an agent (localmodels.js).
|
|
87
|
+
localModels: { enabled: true, context: 32768 },
|
|
85
88
|
// AI News: the frontier labs' latest releases, summarized; see NEWS_DEFAULTS in news.js for every field.
|
|
86
89
|
news: { enabled: true },
|
|
87
90
|
demoPage: false,
|
package/src/engines/codex.js
CHANGED
|
@@ -321,8 +321,8 @@ export default {
|
|
|
321
321
|
* Mark the folder trusted in $CODEX_HOME/config.toml, the record Codex writes for
|
|
322
322
|
* "Trust and continue". Appends a table only when the folder isn't listed yet.
|
|
323
323
|
*/
|
|
324
|
-
trust(dir) {
|
|
325
|
-
const file = path.join(
|
|
324
|
+
trust(dir, codexHome = home()) {
|
|
325
|
+
const file = path.join(codexHome, 'config.toml');
|
|
326
326
|
const key = real(dir).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
327
327
|
let raw = '';
|
|
328
328
|
try {
|
|
@@ -333,7 +333,7 @@ export default {
|
|
|
333
333
|
if (raw.includes(`[projects."${key}"]`)) return false;
|
|
334
334
|
const backup = `${file}.agentmgr-backup`;
|
|
335
335
|
if (raw && !fs.existsSync(backup)) fs.writeFileSync(backup, raw, { mode: 0o600 });
|
|
336
|
-
fs.mkdirSync(
|
|
336
|
+
fs.mkdirSync(codexHome, { recursive: true });
|
|
337
337
|
fs.appendFileSync(file, `${raw && !raw.endsWith('\n') ? '\n' : ''}\n[projects."${key}"]\ntrust_level = "trusted"\n`);
|
|
338
338
|
return true;
|
|
339
339
|
},
|
package/src/engines/index.js
CHANGED
|
@@ -5,10 +5,12 @@ import path from 'node:path';
|
|
|
5
5
|
import antigravity from './antigravity.js';
|
|
6
6
|
import claude from './claude.js';
|
|
7
7
|
import codex from './codex.js';
|
|
8
|
+
import { LOCAL_ENGINES } from './local.js';
|
|
9
|
+
import { localSettings } from '../localmodels.js';
|
|
8
10
|
import muse from './muse.js';
|
|
9
11
|
import { acpEngines } from './acp.js';
|
|
10
12
|
|
|
11
|
-
export const ENGINES = { claude, codex, antigravity, muse };
|
|
13
|
+
export const ENGINES = { claude, codex, antigravity, muse, ...Object.fromEntries(LOCAL_ENGINES.map((e) => [e.id, e])) };
|
|
12
14
|
export const DEFAULT_ENGINE = 'claude';
|
|
13
15
|
|
|
14
16
|
/** Adds an engine from a plugin. Built-in engines can't be replaced. */
|
|
@@ -40,15 +42,28 @@ export function notInstalled(engine, config) {
|
|
|
40
42
|
return `${engine.label} not found: ${where}. ${how}, then run \`agentmgr restart\`. If it's installed somewhere else, set its path in config.json${engine.id === 'claude' ? ' ("claudeBin") or AGENTMGR_CLAUDE_BIN' : ` ("engines": {"${engine.id}": {"bin": "…"}})`}.`;
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The engine "local" stands for: the harness config.json names ("localModels": { "harness": … })
|
|
47
|
+
* when it is installed, else the first installed of OpenCode, Codex and Claude Code. OpenCode
|
|
48
|
+
* first: open models finish a task on it more often than on Codex, whose edit command they get wrong.
|
|
49
|
+
*/
|
|
50
|
+
const LOCAL_ORDER = ['opencode', 'codex', 'claude'];
|
|
51
|
+
export function localEngineId(config = {}) {
|
|
52
|
+
const all = LOCAL_ORDER.map((h) => LOCAL_ENGINES.find((e) => e.harness === h));
|
|
53
|
+
const have = all.filter((e) => installed(e, config));
|
|
54
|
+
return (have.find((e) => e.harness === localSettings(config).harness) ?? have[0] ?? all[0]).id;
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
/** Every engine, with whether it can run here, for pickers and the hub. */
|
|
44
58
|
export function listEngines(config) {
|
|
45
59
|
return Object.values(ENGINES).map((e) => {
|
|
46
|
-
|
|
60
|
+
// Some engines also need something running (a local model server).
|
|
61
|
+
const ok = installed(e, config) && (e.available?.(config) ?? true);
|
|
47
62
|
let notice = null;
|
|
48
63
|
try {
|
|
49
64
|
notice = ok ? (e.notice?.(config) ?? null) : null;
|
|
50
65
|
} catch {}
|
|
51
|
-
return { id: e.id, label: e.label, installed: ok, permissionModes: e.permissionModes, supports: e.supports, notice };
|
|
66
|
+
return { id: e.id, label: e.label, installed: ok, ...(e.local ? { local: true, harness: e.harness } : {}), permissionModes: e.permissionModes, supports: e.supports, notice };
|
|
52
67
|
});
|
|
53
68
|
}
|
|
54
69
|
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Models that run on this computer (Ollama, LM Studio, llama.cpp, MLX: see localmodels.js) as
|
|
2
|
+
// agent engines, one for each harness that can drive them:
|
|
3
|
+
// local-codex the Codex CLI, pointed at the local server instead of OpenAI
|
|
4
|
+
// local-opencode OpenCode (over ACP), given the server as a provider
|
|
5
|
+
// local-claude Claude Code, pointed at the server's Anthropic-style API (Ollama has one;
|
|
6
|
+
// Anthropic doesn't support Claude Code on other models)
|
|
7
|
+
// Each is its harness's engine (sessions, resume, usage, the inbox) with these differences:
|
|
8
|
+
// - The agent's model names the server: "ollama/qwen3-coder:30b".
|
|
9
|
+
// - bin/local-run.js starts the harness: it checks the server answers, on Ollama gives the
|
|
10
|
+
// model room for an agent's context first, and tells the harness where the model is.
|
|
11
|
+
// - Codex runs from a home of its own (~/.agentmanager/codex-local): your plugins and MCP
|
|
12
|
+
// servers would fill a local model's small context before the task starts. Its sessions are
|
|
13
|
+
// kept where Codex keeps yours, and your AGENTS.md is used. Claude Code leaves MCP servers out.
|
|
14
|
+
// - Summaries and reviews stay with an engine that is sure to manage them, and nothing is costed.
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import os from 'node:os';
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { paths } from '../config.js';
|
|
20
|
+
import { lastSeen, localSettings, parseModel } from '../localmodels.js';
|
|
21
|
+
import { acpEngine } from './acp.js';
|
|
22
|
+
import claude from './claude.js';
|
|
23
|
+
import codex from './codex.js';
|
|
24
|
+
|
|
25
|
+
const RUNNER = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'bin', 'local-run.js');
|
|
26
|
+
const SETUP = '--agentmgr-local';
|
|
27
|
+
const codexHome = () => process.env.CODEX_HOME || path.join(os.homedir(), '.codex');
|
|
28
|
+
export const localHome = () => path.join(paths.home, 'codex-local');
|
|
29
|
+
|
|
30
|
+
/** The home Codex runs local models from: its sessions folder and AGENTS.md are your Codex's own. */
|
|
31
|
+
export function ensureLocalHome() {
|
|
32
|
+
const home = localHome();
|
|
33
|
+
fs.mkdirSync(home, { recursive: true });
|
|
34
|
+
const link = (name, { dir = false } = {}) => {
|
|
35
|
+
const target = path.join(codexHome(), name);
|
|
36
|
+
const at = path.join(home, name);
|
|
37
|
+
if (dir) fs.mkdirSync(target, { recursive: true });
|
|
38
|
+
else if (!fs.existsSync(target)) return;
|
|
39
|
+
try {
|
|
40
|
+
if (fs.readlinkSync(at) === target) return;
|
|
41
|
+
fs.unlinkSync(at);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
if (err.code !== 'ENOENT') return; // something of its own is there: leave it
|
|
44
|
+
}
|
|
45
|
+
fs.symlinkSync(target, at, dir ? 'junction' : 'file');
|
|
46
|
+
};
|
|
47
|
+
link('sessions', { dir: true });
|
|
48
|
+
link('AGENTS.md');
|
|
49
|
+
return home;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const bad = (message) => Object.assign(new Error(message), { status: 400 });
|
|
53
|
+
|
|
54
|
+
/** What a launch needs from the config (the servers, the context, the harness's command), carried in the extra arguments. */
|
|
55
|
+
const setupArgs = (config, command) => {
|
|
56
|
+
const s = localSettings(config);
|
|
57
|
+
return [SETUP, JSON.stringify({ command, context: s.context, servers: Object.fromEntries(Object.entries(s.servers).map(([id, x]) => [id, x.url])) })];
|
|
58
|
+
};
|
|
59
|
+
/** The starter's own arguments for a launch, the harness's command, and the other extra arguments. */
|
|
60
|
+
function starter(harness, extra, model) {
|
|
61
|
+
const at = extra.indexOf(SETUP);
|
|
62
|
+
const setup = at < 0 ? null : JSON.parse(extra[at + 1]);
|
|
63
|
+
const m = parseModel(model);
|
|
64
|
+
if (!setup || !m || !setup.servers[m.server]) throw bad('A local agent needs a model, written "<server>/<model>" (see `agentmgr models`)');
|
|
65
|
+
return { head: [RUNNER, '--harness', harness, '--url', setup.servers[m.server], '--model', m.name, '--context', String(setup.context), '--'], command: setup.command, rest: extra.filter((_, i) => i !== at && i !== at + 1) };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** What every local engine shares. */
|
|
69
|
+
const shared = {
|
|
70
|
+
local: true,
|
|
71
|
+
bin: () => process.execPath,
|
|
72
|
+
|
|
73
|
+
/** The model an agent is created with: given or the default, on a known server, able to call tools. */
|
|
74
|
+
checkModel(model, config) {
|
|
75
|
+
const s = localSettings(config);
|
|
76
|
+
const id = String(model ?? '').trim() || s.default;
|
|
77
|
+
if (!id) throw bad('Choose a model for a local agent, written "<server>/<model>": `agentmgr models` lists what runs here');
|
|
78
|
+
const m = parseModel(id);
|
|
79
|
+
if (!m) throw bad(`"${id}" isn't a local model: write "<server>/<model>", say "ollama/${id}"`);
|
|
80
|
+
if (!s.servers[m.server]) throw bad(`No local server named "${m.server}" (known: ${Object.keys(s.servers).join(', ')})`);
|
|
81
|
+
const known = lastSeen()?.find((x) => x.id === m.server)?.models.find((x) => x.id === id);
|
|
82
|
+
if (known && !known.usable) throw bad(`${id}: ${known.notes[0]}`);
|
|
83
|
+
return id;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/** Offered in pickers only while a server with a model an agent can use is running here. */
|
|
87
|
+
available: (config) => localSettings(config).enabled && Boolean(lastSeen()?.some((x) => x.models.some((m) => m.usable))),
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const localCodex = {
|
|
91
|
+
...codex,
|
|
92
|
+
...shared,
|
|
93
|
+
id: 'local-codex',
|
|
94
|
+
harness: 'codex',
|
|
95
|
+
label: 'Local · Codex',
|
|
96
|
+
supports: { ...codex.supports, oneShot: false },
|
|
97
|
+
install: 'Install the Codex CLI, which runs the local model (npm install -g @openai/codex)',
|
|
98
|
+
installedBin: (config) => codex.bin(config),
|
|
99
|
+
extraArgs: (config) => setupArgs(config, [codex.bin(config), ...codex.extraArgs(config)]),
|
|
100
|
+
launchArgs({ extra = [], model, ...opts }) {
|
|
101
|
+
const s = starter('codex', extra, model);
|
|
102
|
+
return [...s.head, s.command[0], ...codex.launchArgs({ ...opts, extra: [...s.command.slice(1), ...s.rest], model: null })];
|
|
103
|
+
},
|
|
104
|
+
env: () => ({ CODEX_HOME: ensureLocalHome() }),
|
|
105
|
+
trust: (dir) => codex.trust(dir, ensureLocalHome()),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const localClaude = {
|
|
109
|
+
...claude,
|
|
110
|
+
...shared,
|
|
111
|
+
id: 'local-claude',
|
|
112
|
+
harness: 'claude',
|
|
113
|
+
label: 'Local · Claude Code',
|
|
114
|
+
// The cost Claude Code works out for a model it doesn't know means nothing.
|
|
115
|
+
supports: { ...claude.supports, cost: false, oneShot: false, planHandoff: false },
|
|
116
|
+
install: 'Install Claude Code, which runs the local model (https://docs.claude.com/en/docs/claude-code)',
|
|
117
|
+
notice: () => "Anthropic doesn't support Claude Code on other models: expect rough edges. The server has to speak Anthropic's API (Ollama does)",
|
|
118
|
+
installedBin: (config) => claude.bin(config),
|
|
119
|
+
extraArgs: (config) => setupArgs(config, [claude.bin(config), ...claude.extraArgs(config)]),
|
|
120
|
+
launchArgs({ extra = [], model, ...opts }) {
|
|
121
|
+
const s = starter('claude', extra, model);
|
|
122
|
+
// MCP servers' tool lists would take much of a local model's context.
|
|
123
|
+
return [...s.head, s.command[0], ...claude.launchArgs({ ...opts, extra: [...s.command.slice(1), ...s.rest, '--strict-mcp-config'], model: null })];
|
|
124
|
+
},
|
|
125
|
+
scan(file, cursor, bugPatterns) {
|
|
126
|
+
const r = claude.scan(file, cursor, bugPatterns);
|
|
127
|
+
return r && 'cost' in r ? { ...r, cost: null } : r;
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const opencode = acpEngine('local-opencode', { command: ['opencode', 'acp'], label: 'Local · OpenCode' });
|
|
132
|
+
/** OpenCode's command: the one config.json gives its ACP engine, if any. */
|
|
133
|
+
const opencodeCommand = (config) => {
|
|
134
|
+
const c = config.acp?.opencode;
|
|
135
|
+
return c?.command ? [c.command, ...(c.args ?? [])].flat().map(String) : ['opencode', 'acp'];
|
|
136
|
+
};
|
|
137
|
+
const localOpencode = {
|
|
138
|
+
...opencode,
|
|
139
|
+
...shared,
|
|
140
|
+
id: 'local-opencode',
|
|
141
|
+
harness: 'opencode',
|
|
142
|
+
// Not one of config's ACP agents: it stays when those are read again.
|
|
143
|
+
acp: false,
|
|
144
|
+
supports: { ...opencode.supports, oneShot: false },
|
|
145
|
+
install: 'Install OpenCode, which runs the local model (npm install -g opencode-ai)',
|
|
146
|
+
installedBin: (config) => opencodeCommand(config)[0],
|
|
147
|
+
extraArgs: (config) => setupArgs(config, opencodeCommand(config)),
|
|
148
|
+
launchArgs({ extra = [], model, ...opts }) {
|
|
149
|
+
const s = starter('opencode', extra, model);
|
|
150
|
+
const client = opencode.launchArgs(opts);
|
|
151
|
+
// Our ACP client, then the agent's command in place of the one the engine was made with.
|
|
152
|
+
return [...s.head, process.execPath, ...client.slice(0, client.lastIndexOf('--') + 1), ...s.command];
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export const LOCAL_ENGINES = [localCodex, localOpencode, localClaude];
|
package/src/git.js
CHANGED
|
@@ -2,8 +2,10 @@ import { execFile, spawn } from 'node:child_process';
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
// Never wait on a username/password prompt nobody can see; fail instead.
|
|
6
|
-
|
|
5
|
+
// Never wait on a username/password prompt nobody can see; fail instead. And no optional locks:
|
|
6
|
+
// a `git status` here in the background would otherwise hold the index lock for a moment, and an
|
|
7
|
+
// agent's own `git add` or `git commit` at that moment fails with "index.lock: File exists".
|
|
8
|
+
const baseEnv = () => ({ ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0' });
|
|
7
9
|
|
|
8
10
|
const cancelled = () => Object.assign(new Error('Cancelled'), { cancelled: true });
|
|
9
11
|
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// Local models: what runs on this computer. Ollama, LM Studio, llama.cpp, MLX and any other server
|
|
2
|
+
// that speaks the OpenAI API are found by asking their usual addresses (and any in config.json's
|
|
3
|
+
// "localModels": { "servers": { "<name>": "<address>" } }), and their models are offered to the
|
|
4
|
+
// "Local model" engine (engines/local.js) as "<server>/<model>", say "ollama/qwen3-coder:30b".
|
|
5
|
+
// Nothing is sent anywhere but those addresses.
|
|
6
|
+
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
|
|
9
|
+
export const LOCAL_DEFAULTS = { enabled: true, context: 32768 };
|
|
10
|
+
export const LOCAL_PRESETS = {
|
|
11
|
+
ollama: { label: 'Ollama', url: 'http://127.0.0.1:11434' },
|
|
12
|
+
lmstudio: { label: 'LM Studio', url: 'http://127.0.0.1:1234' },
|
|
13
|
+
// llama.cpp's llama-server and MLX's mlx_lm.server both start here.
|
|
14
|
+
llamacpp: { label: 'llama.cpp or MLX', url: 'http://127.0.0.1:8080' },
|
|
15
|
+
};
|
|
16
|
+
const KIND_LABEL = { ollama: 'Ollama', lmstudio: 'LM Studio', llamacpp: 'llama.cpp', mlx: 'MLX', openai: 'OpenAI API' };
|
|
17
|
+
export const HARNESSES = ['codex', 'opencode', 'claude'];
|
|
18
|
+
const SERVER_ID = /^[a-z][a-z0-9-]{0,30}$/;
|
|
19
|
+
const MIN_CONTEXT = 8192;
|
|
20
|
+
const MAX_CONTEXT = 1_048_576;
|
|
21
|
+
|
|
22
|
+
/** An address as kept: http(s), no path but what a proxy needs, no trailing "/v1". Null when it isn't one. */
|
|
23
|
+
export function cleanUrl(v) {
|
|
24
|
+
try {
|
|
25
|
+
const u = new URL(String(v ?? '').trim());
|
|
26
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null;
|
|
27
|
+
return `${u.origin}${u.pathname.replace(/\/+$/, '').replace(/\/v1$/, '')}`;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function localSettings(config = {}) {
|
|
34
|
+
const c = config.localModels ?? {};
|
|
35
|
+
const servers = {};
|
|
36
|
+
for (const [id, p] of Object.entries(LOCAL_PRESETS)) servers[id] = { ...p, preset: true };
|
|
37
|
+
for (const [id, v] of Object.entries(c.servers ?? {})) {
|
|
38
|
+
if (!SERVER_ID.test(id)) continue;
|
|
39
|
+
if (v === false) {
|
|
40
|
+
delete servers[id];
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const url = cleanUrl(typeof v === 'string' ? v : v?.url);
|
|
44
|
+
if (url) servers[id] = { label: (typeof v === 'object' && v?.label) || servers[id]?.label || id, url, preset: false };
|
|
45
|
+
}
|
|
46
|
+
const n = Number(c.context);
|
|
47
|
+
return {
|
|
48
|
+
enabled: c.enabled !== false,
|
|
49
|
+
// The room Ollama gives a model for an agent (it starts models with far less); 0 leaves Ollama's own.
|
|
50
|
+
context: n === 0 ? 0 : Number.isInteger(n) && n >= MIN_CONTEXT && n <= MAX_CONTEXT ? n : LOCAL_DEFAULTS.context,
|
|
51
|
+
default: typeof c.default === 'string' && c.default.includes('/') ? c.default : null,
|
|
52
|
+
// The harness "local" stands for; null is the first installed (engines/index.js).
|
|
53
|
+
harness: HARNESSES.includes(c.harness) ? c.harness : null,
|
|
54
|
+
servers,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** "ollama/qwen3-coder:30b" as { server, name }; a model's own name may have slashes. */
|
|
59
|
+
export function parseModel(id) {
|
|
60
|
+
const s = String(id ?? '').trim();
|
|
61
|
+
const at = s.indexOf('/');
|
|
62
|
+
if (at < 1 || at === s.length - 1) return null;
|
|
63
|
+
return { server: s.slice(0, at), name: s.slice(at + 1) };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The copy of an Ollama model with room for an agent: "gpt-oss:20b" with 32768 tokens is
|
|
68
|
+
* "gpt-oss-am32k:20b". A copy is a few lines in Ollama's list; the weights are shared.
|
|
69
|
+
*/
|
|
70
|
+
export function variantName(name, context) {
|
|
71
|
+
const at = name.lastIndexOf(':');
|
|
72
|
+
const tagged = at > name.lastIndexOf('/');
|
|
73
|
+
return `${tagged ? name.slice(0, at) : name}-am${Math.round(context / 1024)}k:${tagged ? name.slice(at + 1) : 'latest'}`;
|
|
74
|
+
}
|
|
75
|
+
const VARIANT = /-am\d+k(:[^/]*)?$/;
|
|
76
|
+
const untagged = (name) => name.replace(/:latest$/, '');
|
|
77
|
+
|
|
78
|
+
/** "20.9B" or "568M" as billions of parameters. */
|
|
79
|
+
const billions = (v) => {
|
|
80
|
+
const m = /^([\d.]+)\s*([BM])/i.exec(String(v ?? ''));
|
|
81
|
+
return m ? Number(m[1]) / (m[2].toUpperCase() === 'M' ? 1000 : 1) : null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** Ollama's /api/tags (and /api/ps, for what is in memory) as models; the copies this app makes are left out. */
|
|
85
|
+
export function ollamaModels(tags, ps = null) {
|
|
86
|
+
// A copy of ours in memory is its model in memory.
|
|
87
|
+
const loaded = new Set((ps?.models ?? []).map((m) => untagged(String(m.name ?? '').replace(/-am\d+k(?=:[^/]*$|$)/, ''))));
|
|
88
|
+
const out = [];
|
|
89
|
+
for (const m of tags?.models ?? []) {
|
|
90
|
+
const name = String(m?.name ?? '');
|
|
91
|
+
if (!name || VARIANT.test(name)) continue;
|
|
92
|
+
const caps = Array.isArray(m.capabilities) ? m.capabilities : null;
|
|
93
|
+
if (caps && !caps.includes('completion')) continue; // an embedding model
|
|
94
|
+
out.push({
|
|
95
|
+
name: untagged(name),
|
|
96
|
+
sizeBytes: Number(m.size) || null,
|
|
97
|
+
params: m.details?.parameter_size ?? null,
|
|
98
|
+
quant: m.details?.quantization_level ?? null,
|
|
99
|
+
// Older Ollama doesn't say here; null is "not known".
|
|
100
|
+
tools: caps ? caps.includes('tools') : null,
|
|
101
|
+
maxContext: Number(m.details?.context_length) || null,
|
|
102
|
+
loaded: loaded.has(untagged(name)),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** LM Studio's /api/v0/models as models. */
|
|
109
|
+
export function lmstudioModels(list) {
|
|
110
|
+
return (list?.data ?? [])
|
|
111
|
+
.filter((m) => m?.id && m.type !== 'embeddings')
|
|
112
|
+
.map((m) => ({
|
|
113
|
+
name: String(m.id),
|
|
114
|
+
sizeBytes: null,
|
|
115
|
+
params: null,
|
|
116
|
+
quant: m.quantization ?? null,
|
|
117
|
+
tools: Array.isArray(m.capabilities) ? m.capabilities.includes('tool_use') : null,
|
|
118
|
+
maxContext: Number(m.max_context_length) || null,
|
|
119
|
+
context: Number(m.loaded_context_length) || null,
|
|
120
|
+
loaded: m.state === 'loaded',
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Any server's /v1/models as models (llama.cpp adds sizes under "meta"). */
|
|
125
|
+
export function openaiModels(list) {
|
|
126
|
+
return (list?.data ?? [])
|
|
127
|
+
.filter((m) => m?.id)
|
|
128
|
+
.map((m) => ({
|
|
129
|
+
name: String(m.id),
|
|
130
|
+
sizeBytes: Number(m.meta?.size) || null,
|
|
131
|
+
params: m.meta?.n_params ? `${(m.meta.n_params / 1e9).toFixed(1)}B` : null,
|
|
132
|
+
quant: null,
|
|
133
|
+
tools: null,
|
|
134
|
+
maxContext: Number(m.meta?.n_ctx_train) || null,
|
|
135
|
+
loaded: m.owned_by === 'llamacpp' ? true : null,
|
|
136
|
+
}));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Whether a model can do an agent's work here, and what to know before choosing it. */
|
|
140
|
+
export function judgeModel(m, { memory = os.totalmem() } = {}) {
|
|
141
|
+
const notes = [];
|
|
142
|
+
if (m.tools === false) return { usable: false, notes: ["Can't call tools, which an agent needs to read and change files"] };
|
|
143
|
+
if (m.sizeBytes && m.sizeBytes > memory * 0.7) notes.push('Large for the memory of this computer: expect it to be slow');
|
|
144
|
+
const b = billions(m.params);
|
|
145
|
+
if (b != null && b < 7) notes.push('Small: fine for a quick question, unlikely to manage a task of many steps');
|
|
146
|
+
if (m.tools == null) notes.push("The server doesn't say whether it can call tools");
|
|
147
|
+
return { usable: true, notes };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function getJson(url, { timeoutMs = 1500 } = {}) {
|
|
151
|
+
try {
|
|
152
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(timeoutMs), headers: { accept: 'application/json' } });
|
|
153
|
+
return res.ok ? await res.json() : null;
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One address: what answers there and its models, or `running: false`. */
|
|
160
|
+
export async function probeServer(id, server, { get = getJson, memory = os.totalmem() } = {}) {
|
|
161
|
+
const base = { id, label: server.label, url: server.url, preset: Boolean(server.preset) };
|
|
162
|
+
const done = (kind, models, more = {}) => ({
|
|
163
|
+
...base,
|
|
164
|
+
label: server.preset && id === 'llamacpp' ? KIND_LABEL[kind] ?? server.label : server.label,
|
|
165
|
+
kind,
|
|
166
|
+
running: true,
|
|
167
|
+
...more,
|
|
168
|
+
models: models.map((m) => ({ id: `${id}/${m.name}`, ...m, ...judgeModel(m, { memory }) })).sort((a, b) => a.name.localeCompare(b.name)),
|
|
169
|
+
});
|
|
170
|
+
const tags = await get(`${server.url}/api/tags`);
|
|
171
|
+
if (Array.isArray(tags?.models)) {
|
|
172
|
+
const [ps, version] = await Promise.all([get(`${server.url}/api/ps`), get(`${server.url}/api/version`)]);
|
|
173
|
+
return done('ollama', ollamaModels(tags, ps), { version: version?.version ?? null });
|
|
174
|
+
}
|
|
175
|
+
const v0 = await get(`${server.url}/api/v0/models`);
|
|
176
|
+
if (Array.isArray(v0?.data)) return done('lmstudio', lmstudioModels(v0));
|
|
177
|
+
const list = await get(`${server.url}/v1/models`);
|
|
178
|
+
if (Array.isArray(list?.data)) {
|
|
179
|
+
const kind = list.data.some((m) => m?.owned_by === 'llamacpp') ? 'llamacpp' : list.data.some((m) => /^mlx-community\//.test(m?.id ?? '')) ? 'mlx' : 'openai';
|
|
180
|
+
return done(kind, openaiModels(list));
|
|
181
|
+
}
|
|
182
|
+
return { ...base, kind: null, running: false, models: [] };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// What the last look found, for checks that can't wait for a new one (engines/local.js).
|
|
186
|
+
let seen = null;
|
|
187
|
+
export const lastSeen = () => seen;
|
|
188
|
+
|
|
189
|
+
/** The servers and their models, looked up again when the last look is older than a few seconds. */
|
|
190
|
+
export class LocalModels {
|
|
191
|
+
constructor({ config, save = () => {}, probe = probeServer, now = () => Date.now(), keepMs = 10_000 }) {
|
|
192
|
+
Object.assign(this, { config, save, probe, now, keepMs, at: 0, pending: null, found: [] });
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get settings() {
|
|
196
|
+
return localSettings(this.config);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async look() {
|
|
200
|
+
const s = this.settings;
|
|
201
|
+
this.found = s.enabled ? await Promise.all(Object.entries(s.servers).map(([id, server]) => this.probe(id, server))) : [];
|
|
202
|
+
this.at = this.now();
|
|
203
|
+
seen = this.found;
|
|
204
|
+
return this.found;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async view({ fresh = false } = {}) {
|
|
208
|
+
if (fresh || this.now() - this.at > this.keepMs) await (this.pending ??= this.look().finally(() => (this.pending = null)));
|
|
209
|
+
const s = this.settings;
|
|
210
|
+
const models = this.found.flatMap((x) => x.models);
|
|
211
|
+
return {
|
|
212
|
+
enabled: s.enabled,
|
|
213
|
+
context: s.context,
|
|
214
|
+
default: s.default,
|
|
215
|
+
memory: os.totalmem(),
|
|
216
|
+
// A server at its usual address that isn't running is not worth a row; one you added is.
|
|
217
|
+
servers: this.found.filter((x) => x.running || !x.preset),
|
|
218
|
+
models: models.filter((m) => m.usable).map((m) => m.id),
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Changes from the API: `enabled`, `context`, `default`, `add: { name, url }`, `remove: name`. */
|
|
223
|
+
change(b = {}) {
|
|
224
|
+
const bad = (m) => Object.assign(new Error(m), { status: 400 });
|
|
225
|
+
const next = { ...this.config.localModels, servers: { ...this.config.localModels?.servers } };
|
|
226
|
+
if ('enabled' in b) next.enabled = b.enabled === true || b.enabled === 'on';
|
|
227
|
+
if ('context' in b) {
|
|
228
|
+
const n = Number(b.context);
|
|
229
|
+
if (!(n === 0 || (Number.isInteger(n) && n >= MIN_CONTEXT && n <= MAX_CONTEXT))) throw bad(`The context is a number of tokens from ${MIN_CONTEXT} to ${MAX_CONTEXT}, or 0 to leave the server's own`);
|
|
230
|
+
next.context = n;
|
|
231
|
+
}
|
|
232
|
+
if ('default' in b) {
|
|
233
|
+
const id = String(b.default ?? '').trim();
|
|
234
|
+
if (id && !parseModel(id)) throw bad('A model is written "<server>/<model>", say "ollama/qwen3-coder:30b"');
|
|
235
|
+
next.default = id || null;
|
|
236
|
+
}
|
|
237
|
+
if ('harness' in b) {
|
|
238
|
+
const h = String(b.harness ?? '').trim().toLowerCase();
|
|
239
|
+
if (h && !HARNESSES.includes(h)) throw bad(`The harness is one of ${HARNESSES.join(', ')}`);
|
|
240
|
+
next.harness = h || null;
|
|
241
|
+
}
|
|
242
|
+
if (b.add) {
|
|
243
|
+
const name = String(b.add.name ?? '').trim().toLowerCase();
|
|
244
|
+
const url = cleanUrl(b.add.url);
|
|
245
|
+
if (!SERVER_ID.test(name)) throw bad('A server\'s name is lowercase letters, digits and "-", starting with a letter');
|
|
246
|
+
if (!url) throw bad('The address is an http or https one, say http://127.0.0.1:8081');
|
|
247
|
+
next.servers[name] = url;
|
|
248
|
+
}
|
|
249
|
+
if (b.remove) {
|
|
250
|
+
const name = String(b.remove).trim().toLowerCase();
|
|
251
|
+
if (!localSettings({ localModels: next }).servers[name]) throw bad(`No server named "${name}"`);
|
|
252
|
+
// One of the usual addresses is switched off; one you added is forgotten.
|
|
253
|
+
if (LOCAL_PRESETS[name]) next.servers[name] = false;
|
|
254
|
+
else delete next.servers[name];
|
|
255
|
+
}
|
|
256
|
+
this.config.localModels = next;
|
|
257
|
+
this.save({ localModels: next });
|
|
258
|
+
this.at = 0;
|
|
259
|
+
}
|
|
260
|
+
}
|
package/src/manager.js
CHANGED
|
@@ -9,7 +9,7 @@ import os from 'node:os';
|
|
|
9
9
|
import path from 'node:path';
|
|
10
10
|
import pty from 'node-pty';
|
|
11
11
|
import { PORT, expandHome, paths } from './config.js';
|
|
12
|
-
import { DEFAULT_ENGINE, ENGINES, engineOf, installed, notInstalled } from './engines/index.js';
|
|
12
|
+
import { DEFAULT_ENGINE, ENGINES, engineOf, installed, localEngineId, notInstalled } from './engines/index.js';
|
|
13
13
|
import {
|
|
14
14
|
DOC_KINDS,
|
|
15
15
|
diagramsOnly,
|
|
@@ -653,8 +653,12 @@ export class AgentManager extends EventEmitter {
|
|
|
653
653
|
}) {
|
|
654
654
|
intent = (intent ?? '').trim();
|
|
655
655
|
const staged = stagedFiles(attachments);
|
|
656
|
+
// "local": a model served on this computer, in the harness chosen for those.
|
|
657
|
+
if (engine === 'local') engine = localEngineId(this.config);
|
|
656
658
|
const engineDef = engineOf(engine || this.config.engine || DEFAULT_ENGINE);
|
|
657
659
|
const engineId = engineDef.id;
|
|
660
|
+
// Some engines need a model, or take only the ones they know (a local model's server and name).
|
|
661
|
+
if (engineDef.checkModel) model = engineDef.checkModel(model, this.config);
|
|
658
662
|
this.plugins.check('agent.create', {
|
|
659
663
|
input: { kind, intent, name, repo, dir, worktree, base, permissionMode: permissionMode || this.config.permissionMode || null, model, project, priority, engine: engineId, imported: Boolean(imported) },
|
|
660
664
|
});
|
|
@@ -1831,7 +1835,9 @@ export class AgentManager extends EventEmitter {
|
|
|
1831
1835
|
}
|
|
1832
1836
|
|
|
1833
1837
|
childEnv(agent) {
|
|
1834
|
-
|
|
1838
|
+
// An engine's own variables (a local model's Codex home, say).
|
|
1839
|
+
const own = agent && Object.hasOwn(ENGINES, agent.engine ?? '') ? ENGINES[agent.engine].env?.(this.config) : null;
|
|
1840
|
+
const env = { ...process.env, ...own, ...(agent ? { AGENTMGR_AGENT_ID: agent.id, AGENTMGR_LEAN_DIR: leanDir(agent.id), ...laneEnv(this.laneFor(agent), laneSettings(this.config)) } : {}), TERM: 'xterm-256color', COLORTERM: 'truecolor', AGENTMGR_TERMINAL: '1', AGENTMGR_USAGE_FILE: usageFile(), AGENTMGR_USER_STATUSLINE: ownStatusLine() };
|
|
1835
1841
|
for (const key of STRIP_ENV) delete env[key];
|
|
1836
1842
|
return env;
|
|
1837
1843
|
}
|
|
@@ -1911,7 +1917,10 @@ export class AgentManager extends EventEmitter {
|
|
|
1911
1917
|
if (mode && !modes.includes(mode)) throw bad(`${engineOf(agent).label} has no "${mode}" mode (use ${modes.join(', ')})`);
|
|
1912
1918
|
allowed.permissionMode = mode;
|
|
1913
1919
|
}
|
|
1914
|
-
if ('model' in fields)
|
|
1920
|
+
if ('model' in fields) {
|
|
1921
|
+
allowed.model = String(fields.model ?? '').trim() || null;
|
|
1922
|
+
if (engineOf(agent).checkModel) allowed.model = engineOf(agent).checkModel(allowed.model, this.config);
|
|
1923
|
+
}
|
|
1915
1924
|
// Keep: clean up never closes or deletes it.
|
|
1916
1925
|
if ('keep' in fields) allowed.keep = Boolean(fields.keep);
|
|
1917
1926
|
if ('budgetUsd' in fields) {
|
package/src/server.js
CHANGED
|
@@ -31,7 +31,8 @@ import { Studio } from './studio.js';
|
|
|
31
31
|
import { Memory } from './memory.js';
|
|
32
32
|
import { doctor } from './doctor.js';
|
|
33
33
|
import { Triggers, tokenMatches } from './triggers.js';
|
|
34
|
-
import { listEngines, registerAcpEngines, registerEngine } from './engines/index.js';
|
|
34
|
+
import { installed, listEngines, localEngineId, registerAcpEngines, registerEngine } from './engines/index.js';
|
|
35
|
+
import { LOCAL_ENGINES } from './engines/local.js';
|
|
35
36
|
import { Plugins, pluginSpecs } from './plugins.js';
|
|
36
37
|
import { HubLink, linkUrls } from './hublink.js';
|
|
37
38
|
import { Notifier, isWorkflowUrl, loadNotify, publicNotify, saveNotify, sendSlack } from './notify.js';
|
|
@@ -57,6 +58,7 @@ import { reaStatus } from './rea.js';
|
|
|
57
58
|
import { EngineUsage, codexWindows } from './usage.js';
|
|
58
59
|
import { leanSettings, leanStats, leanSweep } from './lean.js';
|
|
59
60
|
import { laneOf, laneSettings } from './lanes.js';
|
|
61
|
+
import { LocalModels } from './localmodels.js';
|
|
60
62
|
import { Skills } from './skills.js';
|
|
61
63
|
import { Milestones } from './milestones.js';
|
|
62
64
|
import { Decisions } from './decisions.js';
|
|
@@ -101,7 +103,7 @@ function isAllowedOrigin(origin, port) {
|
|
|
101
103
|
const PUBLIC_REMOTE_API = new Set(['POST /api/login', 'GET /api/session']);
|
|
102
104
|
// Updates are not here: a signed-in device (a phone) can install the newest release too. It only
|
|
103
105
|
// ever installs an official release from where this copy came from (git tag or npm) and restarts.
|
|
104
|
-
const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|shutdown$)/;
|
|
106
|
+
const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|local-models\/settings$|shutdown$)/;
|
|
105
107
|
const HOOK_PATH = '/api/hooks/agents';
|
|
106
108
|
const REPORT_PATH = '/api/agentkit/report';
|
|
107
109
|
const NO_REPO_KINDS = new Set(['general', 'assistant']);
|
|
@@ -115,6 +117,8 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
115
117
|
// ACP agents (Gemini CLI, OpenCode, Goose, … and config's "acp") become engines.
|
|
116
118
|
registerAcpEngines(config);
|
|
117
119
|
const manager = new AgentManager({ store, config, plugins });
|
|
120
|
+
const localModels = new LocalModels({ config, save: saveConfig });
|
|
121
|
+
localModels.view().catch(() => {});
|
|
118
122
|
const backlog = new Backlog({ manager, store, config });
|
|
119
123
|
const proposed = new ProposedIssues({ store, manager });
|
|
120
124
|
const myActions = new MyActions({ store, manager });
|
|
@@ -332,7 +336,8 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
332
336
|
const usage = new EngineUsage({
|
|
333
337
|
store,
|
|
334
338
|
config,
|
|
335
|
-
|
|
339
|
+
// Models served on this computer have no plan and no limits to show.
|
|
340
|
+
engines: () => listEngines(config).filter((e) => !e.local),
|
|
336
341
|
probe: () => manager.readUsage(),
|
|
337
342
|
onChange: () => pushUsage(),
|
|
338
343
|
notify: async (text, plain) => {
|
|
@@ -505,7 +510,10 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
505
510
|
// `closing` while shutting down: it still answers until every agent is closed, then exits.
|
|
506
511
|
api.get('/health', wrap(() => ({ ok: true, pid: process.pid, home: paths.home, claudeBin: config.claudeBin, closing })));
|
|
507
512
|
api.get('/agents', wrap(() => manager.list()));
|
|
508
|
-
api.get('/engines', wrap(() =>
|
|
513
|
+
api.get('/engines', wrap(async () => {
|
|
514
|
+
await localModels.view(); // the "Local model" engine is offered while a server runs here
|
|
515
|
+
return listEngines(config);
|
|
516
|
+
}));
|
|
509
517
|
api.post(
|
|
510
518
|
'/agents',
|
|
511
519
|
wrap((req) => {
|
|
@@ -1261,6 +1269,19 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1261
1269
|
for (const a of store.list()) manager.changed?.(a);
|
|
1262
1270
|
return lanesView();
|
|
1263
1271
|
}));
|
|
1272
|
+
// Local models: the servers running on this computer and their models (localmodels.js). The
|
|
1273
|
+
// settings are changed from this computer only: an address added here is one the daemon asks.
|
|
1274
|
+
// The harnesses that can drive a local model, with the one "local" stands for.
|
|
1275
|
+
const localView = async (opts) => {
|
|
1276
|
+
const v = await localModels.view(opts);
|
|
1277
|
+
const engines = listEngines(config);
|
|
1278
|
+
return { ...v, harness: LOCAL_ENGINES.find((e) => e.id === localEngineId(config)).harness, harnesses: LOCAL_ENGINES.map((e) => ({ id: e.harness, engine: e.id, label: e.label.replace(/^Local · /, ''), installed: installed(e, config), offered: Boolean(engines.find((x) => x.id === e.id)?.installed) })) };
|
|
1279
|
+
};
|
|
1280
|
+
api.get('/local-models', wrap((req) => localView({ fresh: req.query.fresh === '1' })));
|
|
1281
|
+
api.put('/local-models/settings', wrap((req) => {
|
|
1282
|
+
localModels.change(req.body ?? {});
|
|
1283
|
+
return localView({ fresh: true });
|
|
1284
|
+
}));
|
|
1264
1285
|
api.get('/news', wrap(() => news.view()));
|
|
1265
1286
|
api.post('/news/refresh', wrap((req) => {
|
|
1266
1287
|
news.refresh({ search: req.body?.search === true ? true : null }).catch(() => {});
|