Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(model-manager): instructions reach Codex, grid sets itself up, models start with their own app

bitcoinbuilder0f18d6b16f3d
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index c64db04a5..feb777213 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -2113,8 +2113,9 @@ export class BackendSocket {
// ⚠️ Run against grid AS IT STANDS — never set up first. A Grid harness session issues these
// on its own the moment its viewer comes up (every open one, on every daemon start), so
// setting grid up here signed a machine in to grid right after a Harness-only sign-in,
- // with nobody asking. A person sets grid up through the picker's Set up or by opening the
- // Model Manager; until then grid answers these in its own words.
+ // with nobody asking. Grid is set up by the picker's Set up, by making or opening a Model
+ // Manager, and by that harness's own `harness grid setup`; until then grid answers these in
+ // its own words.
void this.gridFleet.run(connId, requestId, request)
.then(result => reply(type, requestId, { ...result }))
.catch(() => reply(type, requestId, { ok: false, code: 1, error: 'Grid command failed unexpectedly.' }))
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index bc2c8cb81..65e9fd54e 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { CompanionZoo, readCompanionIdentity, type CompanionIdentity } from './cable/companionIdentity.js'
-import { ensureBundledModelManager } from './dsh/builtins.js'
+import { MODEL_MANAGER_ID, ensureBundledModelManager } from './dsh/builtins.js'
import { createDeviceStore, deviceStoreAgents } from './lib/autonomous-device/storeRuntime.js'
import { mutateDsh } from './dsh/service.js'
import { HarnessShareOwner } from './sharing/owner.js'
@@ -80,7 +80,7 @@ import { ensureHarnessGrid, type EnsureStatus } from './lib/gridEnsure.js'
import { passThroughToGridLogout } from './lib/gridLogout.js'
import { clearGridMcpUrlCache } from './lib/gridMcpUrl.js'
import { warnIfGridSignInRemains } from './lib/gridCredentials.js'
-import { reconcileGridAttach, gridNamesLocal, createGridAccess } from './lib/gridAttach.js'
+import { reconcileGridAttach, gridNamesLocal, createGridAccess, setUpWithin } from './lib/gridAttach.js'
import { signedInGridEmail, resetGridDeriveMemo } from './lib/gridDerive.js'
import { forgetGridModels, gridAnnotation, keystrokePrewarm, observeMachineList, onGridModelsChanged, warmGridModels } from './lib/gridModels.js'
import { gridAvailable, managedGridPath } from './lib/gridExec.js'
@@ -194,6 +194,7 @@ import { processRows, type DiscoveredTerminalAgent } from './lib/terminalAgentDi
import { remoteCommand } from './remoteCommand.js'
import { tuiCommand } from './tui/index.js'
import { newCommand } from './lib/newCommand.js'
+import { gridSetupCommand } from './lib/gridSetupCommand.js'
import { WebSocket as NewCommandSocket } from 'ws'
import {
terminalActionNotStarted,
@@ -396,6 +397,11 @@ const PROXY_BACKEND_TIMEOUT_MS = 20_000
* stalled control-plane connection cannot hold it open. */
const GRID_MINT_TIMEOUT_MS = 10_000
+/** How long creating a Model Manager waits for grid to be set up before its workspace asks grid which
+ * grid is this account's. Short: the app gives the whole create 20s, and a first install takes minutes.
+ * Past it the set-up carries on, and the agent's own `harness grid setup` waits for it. */
+const MODEL_MANAGER_GRID_WAIT_MS = 8_000
+
/** Between session-binding attempts for a process whose engine store is not resolvable yet. */
const REPAIR_RETRY_MS = 60_000
/** A NEW process is waiting for a session that is about to appear. Muse makes
@@ -456,6 +462,8 @@ Grid (the fleet of AI engines the \`grid\` CLI serves — needs \`grid\` on PATH
no second browser, no second approval
harness grid login --force sign the harness in as a different account first, then the grid
harness grid login --json emit the same machine-readable NDJSON \`harness login --json\` emits
+ harness grid setup have grid ready here through the running daemon: installed, signed in
+ with THIS computer's Harness account, and the account's grid made
harness grid logout [flags] sign out of your grid — the whole of \`grid logout\`, which stops what
this box is serving BEFORE deleting anything. Flags go straight to it:
--force signs out over a serve child it could not confirm stopped
@@ -6165,6 +6173,13 @@ async function runForeground(session: AuthSession | null): Promise<void> {
console.warn(`[agent] create ${dsh} refused · ${detail}`)
return { ok: false, error: 'TMUX_TOO_OLD_FOR_DSH', detail }
}
+ // The Model Manager is grid in use, however it was made (the Store, New Harness, `harness new`, the
+ // models picker): grid is set up before the workspace asks it which grid is this account's.
+ const ensureGrid = backend.ensureGrid
+ if (installed.id === MODEL_MANAGER_ID && ensureGrid) {
+ const setUp = await setUpWithin(() => ensureGrid({ ownGrid: true }), MODEL_MANAGER_GRID_WAIT_MS)
+ if (setUp === 'pending') console.log(`[dsh] ${dsh} · grid is still being set up; the agent waits for it with \`harness grid setup\``)
+ }
try {
dshAccount = { privateGrid: await backend.privateGridName().catch(() => null) }
// Asked BEFORE the template goes in: afterwards every folder has content.
@@ -8616,6 +8631,16 @@ switch (cmd) {
break
case 'grid':
if (args[0] === 'login') gridLoginCommand(flags.includes('--force'), flags.includes('--json')).catch(onError)
+ else if (args[0] === 'setup') {
+ gridSetupCommand({
+ port: daemonPort(),
+ localMachineId: readAuthSession()?.machineId ?? null,
+ daemonRunning: isDaemonRunning,
+ connect: (url) => new NewCommandSocket(url),
+ output: (line) => console.log(line),
+ error: (line) => console.error(line),
+ }).then((code) => { process.exitCode = code }).catch(onError)
+ }
// Everything but the verb, in the order it was typed — a passthrough that allow-listed flags
// would be a second place that has to know what `grid logout` accepts. Only the FIRST `logout`
// token goes: filtering by value instead would eat an option's *value* the day `grid logout`
diff --git a/cli/src/dsh/adapters.ts b/cli/src/dsh/adapters.ts
index 8279b465a..00e757fec 100644
--- a/cli/src/dsh/adapters.ts
+++ b/cli/src/dsh/adapters.ts
@@ -10,11 +10,30 @@ export interface HarnessAdapter {
instructionFiles: readonly string[]
/** A session-local instruction flag, when the engine provides one. */
contextArgs?: (contextFile: string) => string[]
+ /** The session's variables as flags, for an engine whose commands do not inherit its own environment. */
+ envArgs?: (env: Record<string, string>) => string[]
+}
+
+/** What `-c a.b.NAME=…` can address: Codex splits the key on dots, so a name must be a bare key. */
+const CODEX_ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/
+
+/**
+ * Codex runs a session's commands in a shared app server (`codex app-server --managed-daemon`, codex-cli
+ * 0.159.3), not under the process Harness launched, so they never see that process's environment.
+ * Measured: HARNESS_CONTEXT_FILE and every manifest variable were unset in the agent's shell, and the
+ * Model Manager ran without its instructions. `shell_environment_policy.set` is what Codex itself gives
+ * every command, and `-c` carries it to whichever process runs them. The value is a JSON string, which
+ * TOML reads as the same string.
+ */
+export function codexEnvArgs(env: Record<string, string>): string[] {
+ return Object.entries(env)
+ .filter(([name]) => CODEX_ENV_NAME.test(name))
+ .flatMap(([name, value]) => ['-c', `shell_environment_policy.set.${name}=${JSON.stringify(value)}`])
}
export const HARNESS_ADAPTERS = {
claude: { instructionFiles: ['CLAUDE.md'], contextArgs: (file: string) => ['--append-system-prompt', `Read the harness context at ${JSON.stringify(file)} before working.`] },
- codex: { instructionFiles: ['AGENTS.override.md', 'AGENTS.md'] },
+ codex: { instructionFiles: ['AGENTS.override.md', 'AGENTS.md'], envArgs: codexEnvArgs },
cursor: { instructionFiles: ['AGENTS.md'] },
opencode: { instructionFiles: ['AGENTS.md', 'CLAUDE.md'] },
pi: { instructionFiles: ['AGENTS.md', 'CLAUDE.md'], contextArgs: (file: string) => ['--append-system-prompt', file] },
diff --git a/cli/src/dsh/portability.integration.spec.ts b/cli/src/dsh/portability.integration.spec.ts
index cee48e96c..0785ad3bf 100644
--- a/cli/src/dsh/portability.integration.spec.ts
+++ b/cli/src/dsh/portability.integration.spec.ts
@@ -71,6 +71,7 @@ describe('the whole store × engine matrix', () => {
expect(launch.args).toEqual([
...packageArgs.map(arg => expandDshValue(arg, { dsh: dir, workspace })),
...(harnessAdapter(engine).contextArgs?.(launch.env.HARNESS_CONTEXT_FILE!) ?? []),
+ ...(harnessAdapter(engine).envArgs?.(launch.env) ?? []),
])
expect(launch.env.HARNESS_DSH).toBe(pkg.id)
const context = readFileSync(launch.env.HARNESS_CONTEXT_FILE!, 'utf8')
diff --git a/cli/src/dsh/runtime.spec.ts b/cli/src/dsh/runtime.spec.ts
index 48a1c842a..0e0b33781 100644
--- a/cli/src/dsh/runtime.spec.ts
+++ b/cli/src/dsh/runtime.spec.ts
@@ -7,7 +7,7 @@ import { PROCESS_ENGINES } from '../engines/types.js'
import { buildEngineCommandArgv, buildEngineLaunchArgv } from '../lib/engineLaunch.js'
import { buildLaunchOverrides } from '../lib/launchOverrides.js'
import type { InstalledDsh } from './installed.js'
-import { HARNESS_ADAPTERS, HARNESS_BOOTSTRAP, harnessAdapter } from './adapters.js'
+import { HARNESS_ADAPTERS, HARNESS_BOOTSTRAP, codexEnvArgs, harnessAdapter } from './adapters.js'
import { compatibleHarnessEngines } from './compatibility.js'
import { forkRuntimeKey, harnessLaunchOrRefusal, harnessRuntimeDir, incompatibleHarnessEngine, migrateHarnessInstructions, prepareHarnessLaunch } from './runtime.js'
@@ -103,6 +103,19 @@ describe('session isolation and lifecycle', () => {
expect(seen).toBe(result.overrides.env.HARNESS_CONTEXT_FILE)
})
+ it('hands Codex every harness variable as a flag, since its commands run outside the launched process', () => {
+ pkg.manifest.agent!.env = { ...pkg.manifest.agent!.env, QUOTED: 'say "hi" \\ bye', 'NOT-A-KEY': 'x' }
+ const launch = prepareHarnessLaunch(pkg, ws, 'codex', 'env-flags')
+ const set = (name: string) => `shell_environment_policy.set.${name}=${JSON.stringify(launch.env[name])}`
+ for (const name of ['HARNESS_CONTEXT_FILE', 'HARNESS_SKILLS_DIR', 'HARNESS_WORKSPACE', 'HARNESS_DSH', 'TOOLCHAIN']) {
+ expect(launch.args[launch.args.indexOf(set(name)) - 1]).toBe('-c')
+ }
+ expect(launch.args).toContain('shell_environment_policy.set.QUOTED="say \\"hi\\" \\\\ bye"')
+ expect(launch.args.some(arg => arg.includes('NOT-A-KEY'))).toBe(false)
+ // Every other engine runs its commands under the process Harness launched, which already has them.
+ expect(prepareHarnessLaunch(pkg, ws, 'claude', 'env-flags-claude').args.some(arg => arg.startsWith('shell_environment_policy'))).toBe(false)
+ })
+
it('keeps two harnesses in one project separate, leaving no harness content in project rules', () => {
write(join(ws, 'AGENTS.md'), '# My project rules\n')
const a = prepareHarnessLaunch(pkg, ws, 'codex', 'a')
@@ -136,7 +149,7 @@ describe('session isolation and lifecycle', () => {
expect(fork.env.HARNESS_PRIVATE_GRID).toBeUndefined()
const fresh = prepareHarnessLaunch(pkg, ws, 'codex', 'fresh')
expect(readFileSync(fresh.env.HARNESS_CONTEXT_FILE!, 'utf8')).toContain('# Updated instructions')
- expect(fresh.args).toEqual(['--new-flag'])
+ expect(fresh.args).toEqual(['--new-flag', ...codexEnvArgs(fresh.env)])
})
it('keeps older rows stable using their agent id and supports package renames', async () => {
diff --git a/cli/src/dsh/runtime.ts b/cli/src/dsh/runtime.ts
index 70ec70f50..5901de5f1 100644
--- a/cli/src/dsh/runtime.ts
+++ b/cli/src/dsh/runtime.ts
@@ -236,5 +236,5 @@ export function prepareHarnessLaunch(dsh: InstalledDsh, workspace: string, engin
].join('\n')
writeManagedFile(env.HARNESS_CONTEXT_FILE!, context)
if (!existsSync(file)) writeManagedFile(file, `${JSON.stringify(data, null, 2)}\n`)
- return { env, args: [...data.args, ...(adapter.contextArgs?.(env.HARNESS_CONTEXT_FILE!) ?? [])] }
+ return { env, args: [...data.args, ...(adapter.contextArgs?.(env.HARNESS_CONTEXT_FILE!) ?? []), ...(adapter.envArgs?.(env) ?? [])] }
}
diff --git a/cli/src/lib/gridAttach.spec.ts b/cli/src/lib/gridAttach.spec.ts
index 71a303d7a..06f2951ee 100644
--- a/cli/src/lib/gridAttach.spec.ts
+++ b/cli/src/lib/gridAttach.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
-import { reconcileGridAttach, createGridAccess, type GridAttachDeps, type GridAttachResult } from './gridAttach.js'
+import { reconcileGridAttach, createGridAccess, setUpWithin, type GridAttachDeps, type GridAttachResult } from './gridAttach.js'
import type { GridHandoffResult } from './gridHandoff.js'
import type { EnsureResult } from './gridEnsure.js'
@@ -268,3 +268,31 @@ describe('createGridAccess — grid set up when a feature asks', () => {
await expect(grid.ensure()).resolves.toMatchObject({ status: 'handoff-failed', detail: 'boom' })
})
})
+
+describe('setUpWithin: a set-up a create waits for, but not for long', () => {
+ it('answers done once a quick set-up lands', async () => {
+ await expect(setUpWithin(async () => ({ status: 'converged' }), 1_000)).resolves.toBe('done')
+ })
+
+ it('stops waiting at the bound and leaves the set-up running', async () => {
+ vi.useFakeTimers()
+ try {
+ let finish!: () => void
+ const running = new Promise<void>((resolve) => { finish = resolve })
+ let landed = false
+ const waited = setUpWithin(() => running.then(() => { landed = true }), 8_000)
+ await vi.advanceTimersByTimeAsync(8_000)
+ await expect(waited).resolves.toBe('pending')
+ finish()
+ await running
+ await Promise.resolve()
+ expect(landed).toBe(true)
+ } finally {
+ vi.useRealTimers()
+ }
+ })
+
+ it('never throws: a failed set-up is for the next use of grid to say', async () => {
+ await expect(setUpWithin(async () => { throw new Error('offline') }, 1_000)).resolves.toBe('done')
+ })
+})
diff --git a/cli/src/lib/gridAttach.ts b/cli/src/lib/gridAttach.ts
index 34da14927..3b73c0e26 100644
--- a/cli/src/lib/gridAttach.ts
+++ b/cli/src/lib/gridAttach.ts
@@ -240,6 +240,22 @@ export function createGridAccess(opts: GridAccessOptions): GridAccess {
}
}
+/**
+ * Start a grid set-up and wait for it at most [waitMs]. Past that it carries on — the access queue
+ * remembers it when it lands, and a later `ensure` waits for it — so a caller that must answer in seconds
+ * (a Model Manager being created) is never held for a first install. Never throws: what failed is said by
+ * the next thing that uses grid.
+ */
+export async function setUpWithin(setUp: () => Promise<unknown>, waitMs: number): Promise<'done' | 'pending'> {
+ let timer: NodeJS.Timeout | undefined
+ const waited = new Promise<'pending'>((resolve) => { timer = setTimeout(() => resolve('pending'), waitMs) })
+ try {
+ return await Promise.race([setUp().then(() => 'done' as const, () => 'done' as const), waited])
+ } finally {
+ clearTimeout(timer)
+ }
+}
+
export async function gridNamesLocal(): Promise<string[]> {
const { value, result } = await gridJson<Array<{ grid?: unknown }>>(['--remote', 'ls'])
// ⚠️ A FAILED read is NOT an empty list, and conflating the two is how "this machine has no grids"
diff --git a/cli/src/lib/gridSetupCommand.spec.ts b/cli/src/lib/gridSetupCommand.spec.ts
new file mode 100644
index 000000000..5d9b1a4c2
--- /dev/null
+++ b/cli/src/lib/gridSetupCommand.spec.ts
@@ -0,0 +1,80 @@
+import { describe, expect, it } from 'vitest'
+import { EventEmitter } from 'node:events'
+import { gridSetupCommand, type GridSetupDeps } from './gridSetupCommand.js'
+import type { NewSocket } from './newCommand.js'
+
+/** The daemon's loopback socket: `connected` on select, then one answer per request. */
+class FakeSocket extends EventEmitter implements NewSocket {
+ sent: Array<{ type: string; payload: Record<string, unknown> }> = []
+ closed = false
+ constructor(private answer: (frame: { type: string; payload: Record<string, unknown> }) => Record<string, unknown>) {
+ super()
+ }
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ override on(event: string, listener: (...args: any[]) => void): this {
+ super.on(event, listener)
+ if (event === 'open') queueMicrotask(() => this.emit('open'))
+ return this
+ }
+ send(data: string): void {
+ const frame = JSON.parse(data) as { type: string; payload: Record<string, unknown> }
+ this.sent.push(frame)
+ queueMicrotask(() => {
+ if (frame.type === 'machine_select') { this.emit('message', JSON.stringify({ type: 'connected', payload: {} })); return }
+ this.emit('message', JSON.stringify({ type: `${frame.type}_result`, payload: { ...this.answer(frame), requestId: frame.payload.requestId } }))
+ })
+ }
+ close(): void { this.closed = true }
+}
+
+function deps(socket: FakeSocket, over: Partial<GridSetupDeps> = {}): GridSetupDeps & { out: string[]; err: string[] } {
+ const out: string[] = []
+ const err: string[] = []
+ return {
+ port: 1, localMachineId: 'this-mac', daemonRunning: () => true, connect: () => socket,
+ output: (line) => out.push(line), error: (line) => err.push(line), timeoutMs: 200, out, err, ...over,
+ }
+}
+
+describe('harness grid setup', () => {
+ it('asks the daemon for the Set up the models picker asks for, on this computer', async () => {
+ const socket = new FakeSocket(() => ({ models: [] }))
+ const run = deps(socket)
+ expect(await gridSetupCommand(run)).toBe(0)
+ expect(socket.sent.map((frame) => frame.type)).toEqual(['machine_select', 'grid_fleet_models_list'])
+ expect(socket.sent[0]!.payload.machineId).toBe('this-mac')
+ expect(socket.sent[1]!.payload.setup).toBe(true)
+ expect(run.out.join('\n')).toContain('Grid is set up on this computer')
+ expect(socket.closed).toBe(true)
+ })
+
+ it("says why in the daemon's words when the set-up did not finish", async () => {
+ const socket = new FakeSocket(() => ({ models: [], gridSetupNeeded: true, gridSetupError: 'Grid could not be installed. Check the internet connection.' }))
+ const run = deps(socket)
+ expect(await gridSetupCommand(run)).toBe(1)
+ expect(run.err).toEqual(['Grid could not be installed. Check the internet connection.'])
+ expect(run.out).toEqual([])
+ })
+
+ it('does not call a list that still needs a set-up a success', async () => {
+ const run = deps(new FakeSocket(() => ({ models: [], gridSetupNeeded: true })))
+ expect(await gridSetupCommand(run)).toBe(1)
+ expect(run.err.join('\n')).toContain('could not be set up')
+ })
+
+ it('names the one step that is the person’s: a computer not signed in to Harness', async () => {
+ const socket = new FakeSocket(() => ({}))
+ const run = deps(socket, { localMachineId: null })
+ expect(await gridSetupCommand(run)).toBe(1)
+ expect(run.err.join('\n')).toContain('harness login')
+ expect(socket.sent).toEqual([])
+ })
+
+ it('asks nothing of a daemon that is not running', async () => {
+ const socket = new FakeSocket(() => ({}))
+ const run = deps(socket, { daemonRunning: () => false })
+ expect(await gridSetupCommand(run)).toBe(1)
+ expect(run.err.join('\n')).toContain('harness start')
+ expect(socket.sent).toEqual([])
+ })
+})
diff --git a/cli/src/lib/gridSetupCommand.ts b/cli/src/lib/gridSetupCommand.ts
new file mode 100644
index 000000000..2c7125d79
--- /dev/null
+++ b/cli/src/lib/gridSetupCommand.ts
@@ -0,0 +1,48 @@
+import { daemonSession, type NewCommandDeps } from './newCommand.js'
+
+/**
+ * `harness grid setup` — have grid ready on this computer: installed, signed in with this computer's
+ * Harness account (its token, no browser) and the account's own grid there. The same set-up the models
+ * picker's Set up asks for, by the same request, so the running daemon does it once (`lib/gridAttach.ts`
+ * queues and remembers it) rather than this process doing it a second way beside it.
+ *
+ * Run by the Model Manager when grid answers "not signed in" or is not there at all: since grid became an
+ * add-on (#488) nothing sets it up until a grid feature is used, and the sign-in a person can do,
+ * `harness login`, signs in to Harness alone.
+ */
+export interface GridSetupDeps extends Pick<NewCommandDeps, 'port' | 'connect' | 'timeoutMs'> {
+ localMachineId: string | null
+ daemonRunning: () => boolean | Promise<boolean>
+ output: (line: string) => void
+ error: (line: string) => void
+}
+
+/** A first set-up installs grid, which takes minutes; the app's Set up waits as long. */
+export const GRID_SETUP_TIMEOUT_MS = 5 * 60_000
+
+export async function gridSetupCommand(deps: GridSetupDeps): Promise<number> {
+ if (!(await deps.daemonRunning())) {
+ deps.error('Harness is not running on this computer. Start it with `harness start`.')
+ return 1
+ }
+ if (!deps.localMachineId) {
+ deps.error('This computer is not signed in to Harness. Run `harness login`.')
+ return 1
+ }
+ const session = await daemonSession({ ...deps, timeoutMs: deps.timeoutMs ?? GRID_SETUP_TIMEOUT_MS }, deps.localMachineId)
+ try {
+ const reply = await session.request('grid_fleet_models_list', { setup: true })
+ if (typeof reply.gridSetupError === 'string' && reply.gridSetupError) {
+ deps.error(reply.gridSetupError)
+ return 1
+ }
+ if (reply.gridSetupNeeded === true) {
+ deps.error('Grid could not be set up on this computer. Try again.')
+ return 1
+ }
+ deps.output('Grid is set up on this computer, signed in with its Harness account.')
+ return 0
+ } finally {
+ session.close()
+ }
+}
diff --git a/cli/src/lib/newCommand.ts b/cli/src/lib/newCommand.ts
index 8fb68de37..5c2fd8042 100644
--- a/cli/src/lib/newCommand.ts
+++ b/cli/src/lib/newCommand.ts
@@ -238,7 +238,7 @@ const ERRORS: Record<string, string> = {
}
/** One loopback session with the daemon: select the machine, then ask, one request at a time. */
-function daemonSession(deps: NewCommandDeps, machineId: string): Promise<{
+export function daemonSession(deps: Pick<NewCommandDeps, 'port' | 'connect' | 'timeoutMs'>, machineId: string): Promise<{
request: (type: string, payload: Record<string, unknown>) => Promise<Record<string, unknown>>
close: () => void
}> {
diff --git a/store/agents/autonomous-grid/AGENTS.md b/store/agents/autonomous-grid/AGENTS.md
index dfa0286db..e5405d107 100644
--- a/store/agents/autonomous-grid/AGENTS.md
+++ b/store/agents/autonomous-grid/AGENTS.md
@@ -5,7 +5,7 @@ You look after the models on the user's machines — one laptop or a whole fleet
want to run; you find a place for it, start it with the real CLI, verify an answer, and keep the
viewer current. The feature is called **Model Manager**: never say "grid" to
the user, and never hand them a command to type — everything below is something you run when they
-say what they want in plain words. The one exception is `harness login`, when they are not signed in.
+say what they want in plain words. The one exception is `harness login`, when this computer is not signed in to Harness.
**Greet, then listen, then look, then act — in that order.** "hi", "hello", anything with no request
in it gets two lines and one question: who you are in their terms, what you can do here, and the
@@ -41,7 +41,7 @@ engines silently.
1. `"$GRID_FLEET" models --summary` — one short table: this machine (chip, GPUs and whether each is
active, engines installed, what it can run, ports in use), memory and swap now, engines already
answering with their `--at` URL, grids this computer is joined to (`joined`), and one row per model file on disk of every format (size, context,
- cache at 64K, tool calls, vision, which engines read it). Read the table; do not filter it yourself.
+ cache at 64K, tool calls, vision, and START WITH: the engine that starts it). Read the table; do not filter it yourself.
Drop `--summary` for the full JSON only when a field you need is not in the table. The table is
checked: a model folder without "download unfinished" has every weight file on disk, sizes are the
real files' — never re-check with `du`, `find` or `ls` [run: a hand check read the cache's links and
@@ -60,10 +60,17 @@ engines silently.
per token + 0.5 GB within free memory (+3 GB) and the GPU ceiling; tool calls for coding. Nothing
fits: `skills/grid-operations` step 4 (catalog). An engine installed with nothing to serve:
`"$GRID_FLEET" candidates mlx` on a Mac, recipes on a GPU box (`skills/run-local-model`).
-4. Engine by format: GGUF → Grid's own engine; an engine already answering → `join --at http://127.0.0.1:PORT/v1
+4. Engine: the table's START WITH. The app whose folder holds the file starts it, because that app
+ downloaded it and loads it; Grid's engine can be older and refuse a new architecture. `ollama`,
+ `lm-studio` → their `skills/engine-*`; `(start it)` means installed but not running here: start it as
+ its skill says, never switch engines because it is off. `your llama.cpp` → the person's own
+ `llama-server` (path in `installed`): `"$GRID_FLEET" serve llama-P -- PATH -m FILE --alias ALIAS
+ --ctx-size CTX --parallel 1 -ngl 999 --host 127.0.0.1 --port P`, then `"$GRID_FLEET" run -- join GRID
+ --at http://127.0.0.1:P/v1 -m ALIAS --advertise-as ALIAS`; stop it with `leave`, then `"$GRID_FLEET" stop
+ llama-P`. `Grid's llama.cpp` → step 5. `mlx-lm` → `skills/engine-mlx-lm`; `vllm`, `sglang` →
+ `skills/engine-vllm` or `engine-sglang`. An engine already answering → `join --at http://127.0.0.1:PORT/v1
-m ID --advertise-as ALIAS` (the `/v1` is required; without the alias the picker shows the raw id);
- engines already answering that belong to a `joined` grid are not free to reuse; MLX folder → `skills/engine-mlx-lm`; safetensors on an NVIDIA/AMD box →
- `skills/engine-vllm` or `engine-sglang`; Ollama or LM Studio → their `skills/engine-*`.
+ engines already answering that belong to a `joined` grid are not free to reuse.
5. GGUF start: `"$GRID_FLEET" link FILE NAME.gguf` (Grid serves only from `~/.grid/models`; a link, no copy), then
`"$GRID_FLEET" run --thinking off -- join GRID --serve NAME.gguf --advertise-as ALIAS
--ctx-size CTX --endpoint-port PORT --reasoning-budget 0` plus `--max-concurrency 1` on a remote grid or
@@ -75,7 +82,14 @@ engines silently.
the start, without `| tail` or `| head` — it waits by itself and narrates; pass its progress on. Every
engine the same way (Ollama, LM Studio, mlx-lm…: `--kind` is that engine, and after its `join --at`,
`verify --grid GRID --alias ALIAS` proves the relay half). This is the only check: never `sleep`,
- `stats`, `grid chat` or a log in `~/.grid` to find out whether it works [run: 2.5 minutes lost that way]. Report only what passed — an engine that answers but is
+ `stats`, `grid chat` or a log in `~/.grid` to find out whether it works [run: 2.5 minutes lost that way].
+ It also reads the window the engine loaded: `FAIL context` (an Ollama at 16K passed everything else
+ [run]) → `leave GRID --engine ALIAS` first, always. An engine you started: start it again as that
+ line says. One the person was already running is theirs, even when they asked for it by name: ask
+ *Serve its file again at NK (N GB more; theirs keeps running) · Leave it off the grid*.
+ Never keep a model on the grid under 64K, and never get past a FAIL with another form of `verify`
+ [run: an agent ran `--grid` alone, which skips the engine, and served an 8K window].
+ `SKIP context` → the engine does not report it, so say the window was not measured. Report only what passed — an engine that answers but is
not joined is "running here, not in your model picker yet", never "done" — then `fleet models` once more
(swap still climbing a minute later = too big: stop, take a smaller file), `refresh`, and the hand-off.
@@ -97,6 +111,12 @@ and is not local. Kept on this computer only: `"$GRID_CLI" --local start NAME --
`--advertise-host 127.0.0.1` — without it the engine registers this computer's LAN address [run]. **Never run `grid mode`** — it switches
the CLI's mode for every workspace and app on the machine — and never `start` a hosted grid unasked.
A Grid refusal names its own fix: read the whole message and follow it; never open `~/.grid`.
+**Grid not set up on this computer** — `You're not signed in`, `Grid is not installed`, or `init`/`status`
+finding no grid — is yours to fix, never the person's: run `harness grid setup` (it installs Grid when it
+is missing and signs this computer in with its Harness account: no browser, nothing to approve), then
+`"$GRID_FLEET" init`, then carry on with the step that failed. **Never run `grid login`**, whatever a
+refusal says: it opens a second sign-in. Only `harness grid setup` answering that this computer is not
+signed in to Harness is the person's: ask them to sign in to Harness.
The skills hold the detail: `skills/grid-operations/SKILL.md` (grids and access, catalog downloads,
vision, change, stop, move), `skills/run-local-model/SKILL.md` (sizing, choosing, reading official
@@ -123,7 +143,7 @@ problem. Every fleet operation goes through the runner or `$GRID_CLI`: never `ps
`sysctl`, `kill`, llama logs or hand-written scripts to start, stop, inspect or diagnose an engine;
the command's own output is the evidence. Two written exceptions: `"$GRID_FLEET" models`, `recipe`
and `model-facts` read this machine and the engines' official sources for you; and an engine other
-than Grid's own (Ollama, LM Studio, mlx-lm, vLLM, SGLang) is started with `"$GRID_FLEET" serve NAME -- …`
+than Grid's own (Ollama, the person's llama-server, mlx-lm, vLLM, SGLang) is started with `"$GRID_FLEET" serve NAME -- …`
and stopped with `"$GRID_FLEET" stop NAME`, using the command in its `skills/engine-*/SKILL.md`. A plain
`nohup … &` dies when your command returns [run]; `serve` gives the engine its own session and records
its PID, and `stop` kills only that PID.
diff --git a/store/agents/autonomous-grid/lib/connect.mjs b/store/agents/autonomous-grid/lib/connect.mjs
index 7e4a7c3a9..27d6c0608 100644
--- a/store/agents/autonomous-grid/lib/connect.mjs
+++ b/store/agents/autonomous-grid/lib/connect.mjs
@@ -109,7 +109,7 @@ export async function initializeWorkspace(workspace, { runJson = gridJson, selec
config.mode = candidate.mode; config.grid = candidate.grid; source = 'only reachable grid';
}
}
- if (!config.grid) message = candidates.length ? `Ask the user which fleet to use — ${candidates.map(c => c.grid).join(', ')} — then fleet connect --mode local|remote --grid NAME. No private grid of theirs was found, so nothing is chosen for them.` : 'No grid is reachable from this machine. The user signs in to Harness first; then fleet connect --mode local|remote --grid NAME.';
+ if (!config.grid) message = candidates.length ? `Ask the user which fleet to use — ${candidates.map(c => c.grid).join(', ')} — then fleet connect --mode local|remote --grid NAME. No private grid of theirs was found, so nothing is chosen for them.` : 'No grid is reachable from this machine. Run `harness grid setup` (it signs this computer in with its Harness account and makes the account\'s grid), then fleet init again.';
}
if (config.grid) message = `Connected this workspace to ${config.mode} grid ${config.grid}.`;
}
diff --git a/store/agents/autonomous-grid/lib/inventory.mjs b/store/agents/autonomous-grid/lib/inventory.mjs
index a2475af0d..028e4d85d 100644
--- a/store/agents/autonomous-grid/lib/inventory.mjs
+++ b/store/agents/autonomous-grid/lib/inventory.mjs
@@ -142,6 +142,11 @@ export function defaultRoots(env = process.env, home = homedir()) {
{ source: 'lm-studio', path: join(home, '.lmstudio', 'models') },
{ source: 'lm-studio', path: join(home, '.cache', 'lm-studio', 'models') },
{ source: 'huggingface', path: hub },
+ // llama.cpp's own `-hf` downloads: LLAMA_CACHE, else its platform cache folder. Newer builds put them in
+ // the Hugging Face cache above instead (they read HF_HUB_CACHE and HF_HOME), so both are looked at.
+ ...(env.LLAMA_CACHE ? [{ source: 'llama.cpp', path: env.LLAMA_CACHE }] : []),
+ { source: 'llama.cpp', path: join(home, 'Library', 'Caches', 'llama.cpp') },
+ { source: 'llama.cpp', path: join(env.XDG_CACHE_HOME || join(home, '.cache'), 'llama.cpp') },
{ source: 'folder', path: join(home, 'models') },
{ source: 'folder', path: join(home, 'Models') },
{ source: 'folder', path: join(home, 'Downloads'), depth: 3 },
@@ -536,6 +541,35 @@ export function modelFamily(name) {
.split(/[-_.](?=(?:ud|i?q\d[a-z0-9_]*|\d+bit|bf16|f16|f32|fp16|mxfp4|nvfp4|gguf|mlx|awq|gptq)(?:[-_.]|$))/)[0];
}
+/**
+ * The engine a model on disk starts with: the app whose folder holds it, because that app downloaded it
+ * and is known to load it. Grid's engine can be older than the app and refuse a new architecture, so a
+ * file is moved to it only when its own app is not installed. `~/.grid/models`, the Hugging Face cache and
+ * plain folders have no app of their own: GGUF goes to Grid's engine, MLX to mlx-lm, safetensors to vLLM
+ * or SGLang. `running` says whether that app already answers here; `null` engine means nothing here runs it.
+ */
+export function startWith(model, machine, answering = []) {
+ const installed = kind => machine.engines.some(e => e.kind === kind);
+ const yourLlama = machine.engines.find(e => e.kind === 'llama.cpp' && e.note !== "Grid's own engine" && e.version);
+ const up = kind => answering.some(e => e.kind === kind);
+ const grid = { engine: 'llama.cpp', label: "Grid's llama.cpp" };
+ const byFormat = () => {
+ if (model.format === 'gguf') return grid;
+ if (model.format === 'mlx') {
+ if (!machine.canRun.includes('mlx-lm')) return null;
+ return !installed('mlx-lm') && installed('lm-studio') ? { engine: 'lm-studio', label: 'lm-studio', running: up('lm-studio') } : { engine: 'mlx-lm', label: 'mlx-lm' };
+ }
+ const gpu = ['vllm', 'sglang'].filter(kind => machine.canRun.includes(kind));
+ if (!gpu.length) return null;
+ const here = gpu.filter(installed);
+ return { engine: (here[0] ?? gpu[0]), label: here.length ? here.join(' or ') : `${gpu.join(' or ')} (not installed)` };
+ };
+ if (model.source === 'ollama' && installed('ollama')) return { engine: 'ollama', label: 'ollama', running: up('ollama') };
+ if (model.source === 'lm-studio' && installed('lm-studio')) return { engine: 'lm-studio', label: 'lm-studio', running: up('lm-studio') };
+ if (model.source === 'llama.cpp' && yourLlama) return { engine: 'llama.cpp', label: 'your llama.cpp', path: yourLlama.path };
+ return byFormat();
+}
+
/**
* The inventory as a short table an agent reads directly, so it never writes its own filter over the
* JSON (an agent's hand-written `jq` once dropped every MLX model and reported none on disk).
@@ -552,7 +586,7 @@ export function summarize({ machine, engines, models, joined = [] }, contextToke
`joined ${joined.map(j => `${j.grid ?? j.gridId} serving [${j.models.join(', ')}]${j.at ? ` at ${j.at}` : ''}`).join(' · ') || 'none'}${joined.length ? ' — a join to that grid adds to what it serves (Grid 0.3.53+)' : ''}`,
`ports in use ${machine.listeningPorts.join(' ')}`,
'',
- `FORMAT SIZE CONTEXT CACHE@${contextTokens / 1024}K TOOLS VISION READ BY MODEL (where)`,
+ `FORMAT SIZE CONTEXT CACHE@${contextTokens / 1024}K TOOLS VISION START WITH MODEL (where)`,
];
// On Apple silicon with an MLX engine installed, a GGUF that also exists as an MLX folder says so on
// its own row: an agent handed the rule "prefer the MLX copy" still served the GGUF, because nothing
@@ -574,12 +608,14 @@ export function summarize({ machine, engines, models, joined = [] }, contextToke
lines.push([
m.format.padEnd(11), gb(m.bytes).padStart(8), String(facts.contextLength ?? '—').padStart(8),
(kv ? gb(kv * contextTokens) : '—').padStart(10), String(facts.toolCalls ?? '?').padEnd(5), (m.projector ? 'yes' : 'no').padEnd(6),
- m.readableBy.join(',').padEnd(27), `${m.name} (${m.source}${m.alsoAt.length ? `, also ${m.alsoAt.map(a => a.source).join('/')}` : ''})${note ? ` ! ${note}` : ''}`,
+ startLabel(startWith(m, machine, engines)).padEnd(27), `${m.name} (${m.source}${m.alsoAt.length ? `, also ${m.alsoAt.map(a => a.source).join('/')}` : ''})${note ? ` ! ${note}` : ''}`,
].join(' '));
}
return lines.join('\n');
}
+const startLabel = start => (start ? `${start.label}${start.running === undefined ? '' : start.running ? ' (running)' : ' (start it)'}` : '—');
+
/** The whole picture for one start decision: memory now, engines answering, and models on disk. */
export async function inventory({ extraRoots = [], extraPorts = [], env = process.env, home = homedir() } = {}) {
const machine = await machineState({ env, home });
@@ -592,5 +628,5 @@ export async function inventory({ extraRoots = [], extraPorts = [], env = proces
try { grids = JSON.parse(await output(env.GRID_CLI || 'grid', ['ls', '--json'], 8_000)); } catch {}
for (const row of joined) row.grid = (Array.isArray(grids) ? grids : []).find(g => g.id === row.gridId)?.grid ?? null;
}
- return { machine, engines, joined, ...disk };
+ return { machine, engines, joined, ...disk, models: disk.models.map(model => ({ ...model, startWith: startWith(model, machine, engines) })) };
}
diff --git a/store/agents/autonomous-grid/lib/remoteModels.mjs b/store/agents/autonomous-grid/lib/remoteModels.mjs
index b168d4faf..b7e6d3438 100644
--- a/store/agents/autonomous-grid/lib/remoteModels.mjs
+++ b/store/agents/autonomous-grid/lib/remoteModels.mjs
@@ -19,7 +19,8 @@ const NO_NODE = '__GRID_FINDER_NO_NODE__';
// in kilobytes: BusyBox `find` (Alpine) has no `M` suffix [run].
const FALLBACK = [
'for d in ~/.grid/models ~/.ollama/models /usr/share/ollama/.ollama/models ~/.lmstudio/models',
- '~/.cache/lm-studio/models "${HF_HUB_CACHE:-${HF_HOME:-$HOME/.cache/huggingface}/hub}" ~/models ~/Models ~/Downloads;',
+ '~/.cache/lm-studio/models "${HF_HUB_CACHE:-${HF_HOME:-$HOME/.cache/huggingface}/hub}"',
+ '"${LLAMA_CACHE:-$HOME/Library/Caches/llama.cpp}" "${XDG_CACHE_HOME:-$HOME/.cache}/llama.cpp" ~/models ~/Models ~/Downloads;',
'do [ -d "$d" ] && find -L "$d" -maxdepth 8 \\( -iname "*.gguf" -size +51200k -o -name config.json',
'-o -path "*/manifests/*" -type f \\) 2>/dev/null; done | head -300',
].join(' ');
diff --git a/store/agents/autonomous-grid/lib/verify.mjs b/store/agents/autonomous-grid/lib/verify.mjs
index 248308eac..360cb76f1 100644
--- a/store/agents/autonomous-grid/lib/verify.mjs
+++ b/store/agents/autonomous-grid/lib/verify.mjs
@@ -99,27 +99,66 @@ async function answerOnce(fetchImpl, url, { body, log, label, timeoutMs, headers
/** The engine itself, at its own `/v1` URL. */
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
+/** The least context a model here may serve with: every one is for an agent (AGENTS.md step 3). */
+export const MIN_CONTEXT = 65_536;
+const count = value => (Number.isInteger(value) && value > 0 ? value : null);
+const sameId = (a, b) => typeof a === 'string' && typeof b === 'string' && a.toLowerCase() === b.toLowerCase();
+// Ollama names a model without a tag `:latest`, so `llama3` and `llama3:latest` are one model.
+const ollamaName = name => (typeof name === 'string' && !name.includes(':') ? `${name}:latest` : name);
+
+/**
+ * The context the engine loaded the model with, in its own words, or null when it does not say. An
+ * engine already running is adopted as it is, and its window is its owner's setting: an Ollama at 16K
+ * passed every other step here and would have failed the first long prompt [run]. Read after the first
+ * answer, because Ollama and LM Studio load a model on its first request.
+ */
+async function loadedContext({ fetchImpl, base, kind, model, row, log }) {
+ const root = base.replace(/\/v1$/, '');
+ const read = path => call(fetchImpl, `${root}${path}`, { timeoutMs: 5_000, log, label: 'context' });
+ if (kind === 'ollama') {
+ const models = (await read('/api/ps')).json?.models ?? [];
+ const loaded = models.find(entry => [entry.name, entry.model].some(name => sameId(ollamaName(name), ollamaName(model))));
+ return count(loaded?.context_length);
+ }
+ if (kind === 'lm-studio') {
+ const loaded = ((await read('/api/v0/models')).json?.data ?? []).find(entry => sameId(entry.id, model));
+ return count(loaded?.loaded_context_length);
+ }
+ // llama-server reports one request slot's window: --ctx-size divided by --parallel.
+ if (kind === 'llama.cpp') return count((await read('/props')).json?.default_generation_settings?.n_ctx);
+ // vLLM and SGLang list the window they were started with beside the model.
+ return count(row?.max_model_len);
+}
+
+const CONTEXT_FIX = {
+ ollama: 'this Ollama runs every model with that window; leave theirs as it is and start a second Ollama with OLLAMA_CONTEXT_LENGTH (skills/engine-ollama)',
+ 'lm-studio': `load it again with \`lms load MODEL --context-length ${MIN_CONTEXT}\` or more (skills/engine-lm-studio)`,
+ 'llama.cpp': `one you started: start it again with --ctx-size ${MIN_CONTEXT} or more for each request slot (--ctx-size ÷ --parallel); one already running when you came is the person's: ask before serving its file a second time`,
+ vllm: `start it again with --max-model-len ${MIN_CONTEXT} or more (skills/engine-vllm)`,
+ sglang: `start it again with --context-length ${MIN_CONTEXT} or more (skills/engine-sglang)`,
+};
+
export async function verifyEngine({ url, model, kind, readyMs = 180_000, answerMs = 300_000, tools = true, fetchImpl = globalThis.fetch, log = createLog(), sleep = wait }) {
const base = url.replace(/\/+$/, '');
const steps = [];
const record = (name, ok, detail) => { steps.push({ name, ok, ...detail }); log(`${ok ? 'PASS' : 'FAIL'} ${name}${detail.note ? ` — ${detail.note}` : ''}`); return ok; };
if (!/\/v1$/.test(base)) return { ok: false, steps: [{ name: 'url', ok: false, note: 'the URL must end in /v1' }] };
- log(`step 1/4 ready: GET ${base}/models (up to ${readyMs / 1000}s, every 3s)`);
+ log(`step 1/5 ready: GET ${base}/models (up to ${readyMs / 1000}s, every 3s)`);
const deadline = Date.now() + readyMs;
- let listed = null, attempt = 0;
+ let listed = null, rows = [], attempt = 0;
while (Date.now() < deadline) {
attempt++;
const models = await call(fetchImpl, `${base}/models`, { timeoutMs: 5_000, log, label: 'models' });
const ids = (models.json?.data ?? []).map(row => row.id);
- if (models.status === 200) { listed = ids; break; }
+ if (models.status === 200) { listed = ids; rows = models.json?.data ?? []; break; }
if (attempt === 1 || attempt % 5 === 0) log(` attempt ${attempt}: ${models.status || models.text}`);
await sleep(3_000);
}
if (!record('ready', listed !== null, { note: listed === null ? `no 200 from /models within ${readyMs / 1000}s` : `${listed.length} model(s) listed` })) return { ok: false, steps };
if (!record('listed', listed.includes(model), { note: listed.includes(model) ? model : `${model} not in ${JSON.stringify(listed.slice(0, 8))}` })) return { ok: false, steps };
- log(`step 2/4 answer: one request, max_tokens 16, thinking off (up to ${answerMs / 1000}s)`);
+ log(`step 2/5 answer: one request, max_tokens 16, thinking off (up to ${answerMs / 1000}s)`);
const { answer, content, thinkingStaysOn } = await answerOnce(fetchImpl, `${base}/chat/completions`, { timeoutMs: answerMs, log, label: 'answer', body: {
model, max_tokens: 16, temperature: 0, messages: [{ role: 'user', content: 'Reply with the single word: ok' }], ...noThinking(kind) } });
const thinkingOnly = !content && reasoningOf(answer.json);
@@ -127,15 +166,25 @@ export async function verifyEngine({ url, model, kind, readyMs = 180_000, answer
? `${JSON.stringify(content.slice(0, 40))}${thinkingStaysOn ? ` — thinking stays on here: it answers after thinking, slower and with more tokens` : ''}`
: thinkingOnly ? `only reasoning text came back, even with ${THINKING_ROOM} tokens: thinking is still on` : `HTTP ${answer.status}: ${answer.text}` })) return { ok: false, steps };
+ log(`step 3/5 context: the window the engine loaded the model with (at least ${MIN_CONTEXT})`);
+ const context = await loadedContext({ fetchImpl, base, kind, model, row: rows.find(row => row.id === model), log });
+ if (context === null) {
+ // Not seen, so not passed: said as a skip, and the person's own setting stays the word on it.
+ steps.push({ name: 'context', ok: true, skipped: true, note: `${kind || 'this engine'} does not report it` });
+ log(`SKIP context — ${kind || 'this engine'} does not report the window it loaded; say so rather than call it checked`);
+ } else if (!record('context', context >= MIN_CONTEXT, { contextTokens: context, note: context >= MIN_CONTEXT
+ ? `${context} tokens`
+ : `${context} tokens, under ${MIN_CONTEXT}: ${CONTEXT_FIX[kind] ?? `start it again with at least ${MIN_CONTEXT}`}` })) return { ok: false, steps };
+
if (tools) {
- log('step 3/4 tool call: a read_file tool, "Open the file README.md."');
+ log('step 4/5 tool call: a read_file tool, "Open the file README.md."');
const tool = await call(fetchImpl, `${base}/chat/completions`, { timeoutMs: answerMs, log, label: 'tool call', body: {
model, max_tokens: 256, temperature: 0, tools: [TOOL], messages: [{ role: 'user', content: 'Open the file README.md.' }], ...noThinking(kind) } });
const called = message(tool.json).tool_calls?.[0]?.function;
if (!record('tool call', called?.name === 'read_file', { seconds: tool.seconds, note: called ? `${called.name}(${called.arguments})` : `no tool_calls; HTTP ${tool.status}` })) return { ok: false, steps };
- } else log('step 3/4 tool call: skipped');
+ } else log('step 4/5 tool call: skipped');
- log('step 4/4 speed: 128 tokens');
+ log('step 5/5 speed: 128 tokens');
const speed = await call(fetchImpl, `${base}/chat/completions`, { timeoutMs: answerMs, log, label: 'speed', body: {
model, max_tokens: 128, temperature: 0, messages: [{ role: 'user', content: 'Count from 1 to 60 in words.' }], ...noThinking(kind) } });
const reported = speed.json?.timings?.predicted_per_second;
@@ -146,6 +195,17 @@ export async function verifyEngine({ url, model, kind, readyMs = 180_000, answer
return { ok: steps.every(step => step.ok), steps };
}
+/**
+ * Why `verify --grid --alias` alone may not check this alias, or null. That form is for an engine on
+ * another machine, which has no URL here to check; for one served from this computer it skips every
+ * engine step, context included, and an agent that had just seen `FAIL context` ran it to get a pass
+ * [run]. `rows` are `grid models` rows, whose `node` is the machine name every join is given.
+ */
+export function relayOnlyRefusal(rows, alias, localName) {
+ const here = (Array.isArray(rows) ? rows : []).find(row => sameId(row?.model ?? row?.id, alias) && localName && row?.node === localName);
+ return here ? `${alias} is served from this computer (${localName}): check its engine with --at http://127.0.0.1:PORT/v1 --model ID --kind ENGINE as well. --grid with --alias alone is for an engine on another machine.` : null;
+}
+
/** After a join: the relay must list the alias, then answer through the grid's own endpoint. */
export async function verifyRelay({ alias, engineModel, listModels, relay, listMs = 300_000, answerMs = 420_000, fetchImpl = globalThis.fetch, log = createLog(), sleep = wait }) {
const steps = [];
diff --git a/store/agents/autonomous-grid/skills/engine-lm-studio/SKILL.md b/store/agents/autonomous-grid/skills/engine-lm-studio/SKILL.md
index 1573d098c..f4fee0ede 100644
--- a/store/agents/autonomous-grid/skills/engine-lm-studio/SKILL.md
+++ b/store/agents/autonomous-grid/skills/engine-lm-studio/SKILL.md
@@ -18,11 +18,14 @@ Tags: `[doc]` official page above, `[run]` seen on the tested machine, `[?]` unv
## When to use it
-- **Its server is answering** (`fleet models` → `kind: lm-studio`): adopt it, but load the model
- yourself with a 64K+ context (below) — a model it loads on demand gets 8192 [run], too small for an agent.
-- **An MLX model sits in LM Studio's folder and mlx-lm is not installed**: LM Studio runs MLX on Apple
- silicon (its structured output uses Outlines for MLX [doc]), so use it instead of installing anything.
-- **A GGUF in LM Studio's folder**: Grid's own engine serves it in place; LM Studio need not run.
+- **A model in LM Studio's folder**, GGUF or MLX (`fleet models` → START WITH `lm-studio`): LM Studio runs
+ it, because it downloaded it and loads it.
+ - **Its server answering**: adopt it, but load the model yourself with a 64K+ context (below) — a model
+ it loads on demand gets 8192 [run], too small for an agent.
+ - **`(start it)`**: start its server yourself (below); an LM Studio that is off is the normal case, not
+ a reason to switch engines.
+- **An MLX model elsewhere and mlx-lm not installed**: LM Studio runs MLX on Apple silicon (its
+ structured output uses Outlines for MLX [doc]), so use it instead of installing anything.
- Never install LM Studio just to serve a model: Grid's engine covers GGUF, mlx-lm covers MLX.
## Where its models live / how to list them
@@ -63,7 +66,7 @@ Run `"$GRID_FLEET" verify --at http://127.0.0.1:P/v1 --model <id> --kind lm-stud
request checks with deadlines and prints each one. Also:
1. `lms server status` shows port P [run]. 2. `GET http://127.0.0.1:P/v1/models` lists `<id>` [doc][run].
-3. `lms ps` shows `<id>` with CONTEXT ≥ 65536 [run]. 4. One bounded `/v1/chat/completions` request with
+3. LM Studio reports `<id>` loaded with ≥ 65536 (`/api/v0/models`, the CONTEXT `lms ps` shows) [run]. 4. One bounded `/v1/chat/completions` request with
`model: <id>`, `max_tokens` 16 → non-empty `content` [run].
A 401 means the person turned on "Require Authentication" [doc]: do not change their setting; say so and
serve the file with Grid's engine instead.
diff --git a/store/agents/autonomous-grid/skills/engine-ollama/SKILL.md b/store/agents/autonomous-grid/skills/engine-ollama/SKILL.md
index 8768209c8..91c6e5e31 100644
--- a/store/agents/autonomous-grid/skills/engine-ollama/SKILL.md
+++ b/store/agents/autonomous-grid/skills/engine-ollama/SKILL.md
@@ -16,19 +16,17 @@ Tags: `[doc]` official page above, `[run]` seen on the tested machine, `[?]` unv
## When to use it
-- **Ollama is already answering** (`fleet models` lists `kind: ollama`): adopt it as it is; it is the
- person's app, so never restart or reconfigure it without asking.
-- **The person asked for Ollama and it is not running**: start it yourself (below) — it is theirs to
- want, and an engine that is off is the normal case, not a reason to switch [run].
-- **Ollama is stopped and nobody asked for it**: leave it off. Its models are GGUF files that Grid's
- engine serves in place — link the blob into `~/.grid/models` and `join --serve` [run], with the
- context you choose instead of Ollama's default.
-- Start Ollama unasked only when Grid's engine refuses a blob Ollama runs (Ollama ships its own engine
- for some new architectures [?]).
+- **A model in Ollama's store** (`fleet models` → START WITH `ollama`): Ollama runs it. It downloaded the
+ file and ships its own engine for new architectures, which Grid's engine can refuse [?].
+ - **Answering**: adopt it as it is; it is the person's app, so never restart or reconfigure it.
+ - **`(start it)`**: start one yourself (below). An Ollama that is off is the normal case, not a reason
+ to switch engines [run].
+- **Ollama not installed**: its blobs are GGUF files, so `fleet models` names Grid's llama.cpp — link the
+ blob into `~/.grid/models` and `join --serve` [run].
- A GGUF from another app enters Ollama only by `ollama create` (a `Modelfile` with `FROM <file>`), and
that **copies the whole file** into Ollama's store (+624 MB for a 640 MB GGUF) [run]. So never do it
unasked; when the person wants Ollama and it has nothing suitable, offer it with the size it adds on
- disk, beside the no-copy choice (the same file on Grid's engine). Never `ollama pull` without the
+ disk, beside the no-copy choice (the file with its own app). Never `ollama pull` without the
go-ahead: it downloads.
## MLX inside Ollama (Apple silicon)
@@ -63,9 +61,10 @@ importing other MLX models is not yet documented [?].
the Linux installer creates a systemd service `ollama` [doc].
- Running: `fleet models` → `engines[]` with `kind: ollama`. Default bind is 127.0.0.1:11434 [doc].
-## Start an already-downloaded model (only when Grid's engine refused it)
+## Start an already-downloaded model (Ollama not running, or running with too small a window)
-Port P from outside `machine.listeningPorts`; the port is set only through `OLLAMA_HOST` (no `--port`) [doc]:
+Port P from outside `machine.listeningPorts`, and never 11434: that is the Ollama app's own, and it must
+still start when the person opens it [run]. The port is set only through `OLLAMA_HOST` (no `--port`) [doc]:
"$GRID_FLEET" serve ollama-P --env OLLAMA_HOST=127.0.0.1:P --env OLLAMA_CONTEXT_LENGTH=65536 -- ollama serve
@@ -87,7 +86,9 @@ these checks with deadlines and prints each one. What it checks:
1. The PID is alive. 2. `GET /` answers "Ollama is running" [run]. 3. `GET /api/version` → 200 [run].
4. One bounded request through `/v1/chat/completions` with the model id, `max_tokens` 16 and
`"reasoning_effort":"none"` for a thinking model → non-empty `content` [doc][run].
-Then `GET /api/ps` must show the model with `context_length` ≥ 65536 [doc]; less is not started.
+5. `GET /api/ps` shows the model with `context_length` ≥ 65536 [doc]. `FAIL context` means this Ollama
+ runs every model with that window [run]: `leave` the grid, then leave their Ollama as it is and start a
+ second one with `OLLAMA_CONTEXT_LENGTH` (above) [run].
## Join Harness Compute
@@ -130,7 +131,7 @@ records JSON output as unsupported without any error [run]. Grid's own detector
|---|---|
| 404 on `/models` or `/chat/completions` | the URL lacks `/v1` [run] |
| `content` empty, `thinking` full | add `reasoning_effort: "none"` [doc] |
-| `/api/ps` context below 65536 | the person's Ollama runs its default (4K or 32K); serve the blob with Grid's engine instead of changing their app |
+| `/api/ps` context below 65536 | the person's Ollama runs its default (4K or 32K); start a second Ollama with `OLLAMA_CONTEXT_LENGTH` instead of changing their app |
| 503 "server is overloaded" | queue full (`OLLAMA_MAX_QUEUE`, default 512) [doc]; wait, do not retry in a loop |
| `PROCESSOR` shows CPU share | model plus context does not fit the GPU; smaller context or model [doc] |
| model not found | not downloaded; offer the download as a slow step, never pull silently |
diff --git a/store/agents/autonomous-grid/skills/grid-operations/SKILL.md b/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
index cdb86692f..f5287868c 100644
--- a/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
+++ b/store/agents/autonomous-grid/skills/grid-operations/SKILL.md
@@ -44,8 +44,9 @@ a request that says "my grid" goes to `personalGrid`, whatever is selected, and
names no grid at all ("run a model on my Mac"). The `type` column of
`ls --json` is what kind of grid a row is, not a permission to ask about: `permissioned-public` is
a person's own grid, `private-domain` a company's, `domain-restricted` a team's, `os-community` a
-public one. Only when `personalGrid` is null: say in one line that Harness has not named this
-account's grid yet and ask them to sign in to Harness — never pick one from `ls`.
+public one. Only when `personalGrid` is null: run `harness grid setup` (it makes the account's grid)
+and `"$GRID_FLEET" init` (it records it); still null → say in one line that this account's grid could
+not be found — never pick one from `ls`.
Connect with
`"$GRID_FLEET" connect --mode remote --grid NAME --remember` to select a verified grid and reuse it
in future workspaces. `--remember` writes this controller's `~/.harness/grid-fleet/default.json`;
@@ -293,7 +294,11 @@ move is enough to carry it through without asking again.
Say what failed and stop; translate every message, never repeat a raw line that names the CLI.
- - **Not signed in** → the user's to fix: `harness login`, the only command ever theirs.
+ - **`You're not signed in`** or **`Grid is not installed`** → yours, never the person's: `harness grid
+ setup` (installs Grid when missing and signs this computer in with its Harness account, no browser),
+ then `"$GRID_FLEET" init`, then the step again. Never `grid login`: it is a second sign-in. Only
+ `harness grid setup` saying this computer is not signed in to Harness is theirs: `harness login`,
+ the only command ever theirs.
- **`No providers available for this model`** right after a join → not registered yet; wait as
step 6 says.
- **`exceeds the available context size`** (an agent may show it as a garbled "expected array
diff --git a/store/agents/autonomous-grid/test/connect.test.mjs b/store/agents/autonomous-grid/test/connect.test.mjs
index 1da5d9df4..e44ad9b7d 100644
--- a/store/agents/autonomous-grid/test/connect.test.mjs
+++ b/store/agents/autonomous-grid/test/connect.test.mjs
@@ -62,6 +62,14 @@ test('the collector follows a changed selection on its next poll',async t=>{
assert.equal((await readConfig(dir)).grid,'tuan-dev-991371e4');
assert.ok(asked.some(a=>a[0]==='engines'&&a[1]==='tuan-dev-991371e4'),'the new grid is what gets polled');
});
+test('grid signed out answers nothing, and the agent is told to set grid up itself, not to send the person to sign in',async t=>{
+ const {dir,profilePath}=await setup(t);
+ const signedOut={ok:false,error:"You're not signed in. Run `grid login` to sign in."};
+ const result=await initializeWorkspace(dir,{profilePath,discover,runJson:async()=>signedOut,email:async()=>null,env:{HARNESS_PRIVATE_GRID:'tuan-dev-991371e4'}});
+ assert.equal(result.config.grid,null);assert.equal(result.config.personalGrid,'tuan-dev-991371e4');
+ assert.match(result.connection.message,/harness grid setup/);assert.match(result.connection.message,/fleet init/);
+ assert.doesNotMatch(result.connection.message,/signs? in to Harness|grid login/);
+});
test('no private grid and an ambiguous inventory selects nothing and tells the agent to ask',async t=>{
const {dir,profilePath}=await setup(t);
const runJson=async(_host,mode,args)=>args[0]==='mode'?{ok:true,value:{mode:'remote'}}:args[0]==='engines'?{ok:false,error:'unreachable'}:{ok:true,value:mode==='local'?[{grid:'home'}]:[{grid:'working'},{grid:'other'}]};
diff --git a/store/agents/autonomous-grid/test/inventory.test.mjs b/store/agents/autonomous-grid/test/inventory.test.mjs
index d1a02973c..4152859d0 100644
--- a/store/agents/autonomous-grid/test/inventory.test.mjs
+++ b/store/agents/autonomous-grid/test/inventory.test.mjs
@@ -5,7 +5,7 @@ import { mkdir, mkdtemp, symlink, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import {
- defaultRoots, joinedGrids, modelFamily, parseListDevices, parseListeningPorts, parseMeminfo, parseNetstatListening,
+ defaultRoots, joinedGrids, startWith, modelFamily, parseListDevices, parseListeningPorts, parseMeminfo, parseNetstatListening,
parseProcNetTcp, parseSwapUsage, parseVmStat,
probeEngines, readGguf, scanModels, summarize, summarizeGguf,
} from '../lib/inventory.mjs';
@@ -75,10 +75,15 @@ test('scan finds models other apps downloaded, names them, and reports one entry
await put(join(home, 'models', 'plain', 'config.json'), JSON.stringify({ architectures: ['LlamaForCausalLM'], max_position_embeddings: 8192 }));
await put(join(home, 'models', 'plain', 'model-00001-of-00001.safetensors'), 'weights');
await put(join(home, 'Downloads', 'notes.txt'), 'not a model');
+ // `llama-server -hf org/repo` before llama.cpp moved its downloads into the Hugging Face cache.
+ await put(join(home, 'Library', 'Caches', 'llama.cpp', 'org_Widget-3B-GGUF_Widget-3B-Q4_K_M.gguf'), tiny('llama'));
+ await put(join(home, 'Library', 'Caches', 'llama.cpp', 'org_Widget-3B-GGUF_Widget-3B-Q4_K_M.gguf.json'), '{}');
const { models } = await scanModels({ roots: defaultRoots({}, home).filter(root => root.path.startsWith(home)), minBytes: 0 });
const byName = Object.fromEntries(models.map(model => [model.name, model]));
- assert.equal(models.length, 4);
+ assert.equal(models.length, 5);
+ assert.equal(byName['org_Widget-3B-GGUF_Widget-3B-Q4_K_M'].source, 'llama.cpp');
+ assert.ok(byName['org_Widget-3B-GGUF_Widget-3B-Q4_K_M'].readableBy.includes('llama.cpp'));
assert.equal(byName['qwen2.5-0.5b'].source, 'grid');
assert.deepEqual(byName['qwen2.5-0.5b'].alsoAt.map(seen => [seen.source, seen.name]), [['ollama', 'qwen2.5:0.5b']]);
assert.equal(byName['Model-7B-Q4_K_M'].quant, 'Q4_K_M');
@@ -235,3 +240,48 @@ test('a model no engine on this machine can run says so, instead of looking usab
assert.match(text, /org\/Model-4bit .*! no engine this machine can run reads mlx \(Apple silicon only\)/);
assert.doesNotMatch(text, /model-q4 .*no engine/);
});
+
+test('llama.cpp downloads are looked for where llama.cpp keeps them: LLAMA_CACHE, else its cache folder', () => {
+ const home = '/home/me';
+ const llama = env => defaultRoots(env, home).filter(root => root.source === 'llama.cpp').map(root => root.path);
+ assert.deepEqual(llama({}), ['/home/me/Library/Caches/llama.cpp', '/home/me/.cache/llama.cpp']);
+ assert.deepEqual(llama({ LLAMA_CACHE: '/data/llama', XDG_CACHE_HOME: '/xdg' }), ['/data/llama', '/home/me/Library/Caches/llama.cpp', '/xdg/llama.cpp']);
+});
+
+test('a model starts with the app whose folder holds it, and moves to Grid\'s engine only when that app is gone', () => {
+ const grid = { kind: 'llama.cpp', path: '/home/me/.grid/bin/llama-server', version: 'version: 10369', note: "Grid's own engine" };
+ const mac = (...engines) => ({ engines: [grid, ...engines], canRun: ['llama.cpp', 'mlx-lm', 'ollama', 'lm-studio'] });
+ const ollama = { kind: 'ollama', path: '/usr/local/bin/ollama', version: '0.32.5' };
+ const studio = { kind: 'lm-studio', path: '/home/me/.lmstudio/bin/lms', version: null };
+ const yours = { kind: 'llama.cpp', path: '/opt/homebrew/bin/llama-server', version: 'version: 9000' };
+ const model = (source, format = 'gguf') => ({ source, format });
+ // Ollama's store: Ollama, said running or not, so a stopped Ollama is started rather than skipped.
+ assert.deepEqual(startWith(model('ollama'), mac(ollama)), { engine: 'ollama', label: 'ollama', running: false });
+ assert.equal(startWith(model('ollama'), mac(ollama), [{ kind: 'ollama', url: 'http://127.0.0.1:11434/v1' }]).running, true);
+ assert.equal(startWith(model('ollama'), mac()).label, "Grid's llama.cpp", 'Ollama uninstalled: its blob is still a GGUF');
+ // LM Studio's folder, GGUF or MLX: LM Studio; without it, by format.
+ assert.equal(startWith(model('lm-studio'), mac(studio)).engine, 'lm-studio');
+ assert.equal(startWith(model('lm-studio', 'mlx'), mac(studio, { kind: 'mlx-lm', path: '/x/mlx_lm.server', version: '0.31' })).engine, 'lm-studio');
+ assert.equal(startWith(model('lm-studio'), mac()).label, "Grid's llama.cpp");
+ // llama.cpp's cache: the person's own llama-server, which downloaded it; Grid's when they have none.
+ assert.deepEqual(startWith(model('llama.cpp'), mac(yours)), { engine: 'llama.cpp', label: 'your llama.cpp', path: '/opt/homebrew/bin/llama-server' });
+ assert.equal(startWith(model('llama.cpp'), mac()).label, "Grid's llama.cpp");
+ // ~/.grid/models stays Grid's, whatever else is installed.
+ assert.equal(startWith(model('grid'), mac(ollama, studio, yours)).label, "Grid's llama.cpp");
+ // No app of its own: by format. Safetensors go to vLLM or SGLang where they run, and to nothing on a Mac.
+ const gpuBox = { engines: [grid, { kind: 'vllm', path: '/x/vllm', version: '0.12' }], canRun: ['llama.cpp', 'ollama', 'vllm', 'sglang'] };
+ assert.equal(startWith(model('huggingface', 'safetensors'), gpuBox).label, 'vllm');
+ assert.equal(startWith(model('folder', 'safetensors'), { ...gpuBox, engines: [grid] }).label, 'vllm or sglang (not installed)');
+ assert.equal(startWith(model('huggingface', 'safetensors'), mac()), null);
+ assert.equal(startWith(model('huggingface', 'mlx'), mac({ kind: 'mlx-lm', path: '/x', version: '0.31' })).engine, 'mlx-lm');
+});
+
+test('the table names the engine each model starts with, and whether it must be started first', () => {
+ const machine = { platform: 'darwin', arch: 'arm64', accelerators: [], listeningPorts: [], canRun: ['llama.cpp', 'mlx-lm', 'ollama', 'lm-studio'],
+ engines: [{ kind: 'llama.cpp', path: '/g/llama-server', version: 'v', note: "Grid's own engine" }, { kind: 'ollama', path: '/o', version: '0.32.5' }] };
+ const row = { format: 'gguf', bytes: 2e9, gguf: { contextLength: 131072, toolCalls: true }, readableBy: ['llama.cpp', 'ollama', 'lm-studio'], alsoAt: [], projector: null };
+ const text = summarize({ machine, engines: [], models: [{ ...row, name: 'llama3.2:3b', source: 'ollama' }, { ...row, name: 'Widget-Q4_K_M', source: 'grid' }] });
+ assert.match(text, /START WITH/);
+ assert.match(text, /ollama \(start it\)\s+llama3\.2:3b \(ollama\)/);
+ assert.match(text, /Grid's llama\.cpp\s+Widget-Q4_K_M \(grid\)/);
+});
diff --git a/store/agents/autonomous-grid/test/verify.test.mjs b/store/agents/autonomous-grid/test/verify.test.mjs
index f2a426e2b..3ca7b8b38 100644
--- a/store/agents/autonomous-grid/test/verify.test.mjs
+++ b/store/agents/autonomous-grid/test/verify.test.mjs
@@ -1,17 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
-import { createLog, verifyEngine, verifyRelay } from '../lib/verify.mjs';
+import { createLog, relayOnlyRefusal, verifyEngine, verifyRelay } from '../lib/verify.mjs';
const json = (body, status = 200) => new Response(JSON.stringify(body), { status });
const quiet = () => {};
const instant = async () => {};
-function engine({ bootFailures = 1, content = 'ok', reasoning = '', toolCall = true, seen = [], thinksFirst = false } = {}) {
+function engine({ bootFailures = 1, content = 'ok', reasoning = '', toolCall = true, seen = [], thinksFirst = false, row = { id: 'widget' }, reports = {} } = {}) {
let boots = 0;
return async (url, init = {}) => {
const body = init.body ? JSON.parse(init.body) : null;
seen.push({ url, body });
- if (url.endsWith('/models')) return boots++ < bootFailures ? new Response('loading', { status: 503 }) : json({ data: [{ id: 'widget' }] });
+ // An engine's own report of what it loaded (Ollama /api/ps, LM Studio /api/v0/models, llama.cpp /props).
+ const path = new URL(url).pathname;
+ if (path in reports) return json(reports[path]);
+ if (!path.startsWith('/v1/')) return new Response('not found', { status: 404 });
+ if (url.endsWith('/models')) return boots++ < bootFailures ? new Response('loading', { status: 503 }) : json({ data: [row] });
if (body.tools) return json({ choices: [{ message: toolCall ? { tool_calls: [{ function: { name: 'read_file', arguments: '{"path":"README.md"}' } }] } : { content: 'I cannot' } }] });
if (body.max_tokens === 128) return json({ usage: { completion_tokens: 128 }, timings: { predicted_per_second: 21.5 }, choices: [{ message: { content: 'one two' } }] });
// A model an engine keeps thinking: 16 tokens are all reasoning, a larger budget reaches the answer.
@@ -24,7 +28,7 @@ test('an engine passes only after ready, listed, a real answer, a tool call and
const lines = [], seen = [];
const result = await verifyEngine({ url: 'http://127.0.0.1:9/v1', model: 'widget', fetchImpl: engine({ seen }), log: createLog(line => lines.push(line)), sleep: instant });
assert.equal(result.ok, true);
- assert.deepEqual(result.steps.map(step => step.name), ['ready', 'listed', 'answer', 'tool call', 'speed']);
+ assert.deepEqual(result.steps.map(step => step.name), ['ready', 'listed', 'answer', 'context', 'tool call', 'speed']);
assert.equal(result.steps.at(-1).tokensPerSecond, 21.5);
assert.ok(lines.some(line => /attempt 1: 503/.test(line)), 'a failed readiness attempt is shown, not hidden');
assert.ok(lines.every(line => /^\[\+\s*\d+s\]/.test(line)), 'every line carries elapsed time');
@@ -99,3 +103,47 @@ test('an alias the relay lists in another case passes at once, and is asked by t
assert.equal(polls, 1);
assert.equal(asked, 'LFM2.5-VL-3B');
});
+
+test('an Ollama already running with a short window fails on context, with the fix, before anything is called working', async () => {
+ const lines = [];
+ const reports = { '/api/ps': { models: [{ name: 'llama3.2:3b', model: 'llama3.2:3b', context_length: 16384 }] } };
+ const result = await verifyEngine({ url: 'http://127.0.0.1:11434/v1', model: 'llama3.2:3b', kind: 'ollama', fetchImpl: engine({ bootFailures: 0, row: { id: 'llama3.2:3b' }, reports }), log: createLog(line => lines.push(line)), sleep: instant });
+ assert.equal(result.ok, false);
+ const context = result.steps.at(-1);
+ assert.equal(context.name, 'context');
+ assert.equal(context.contextTokens, 16384);
+ assert.match(context.note, /16384 tokens, under 65536: .*start a second Ollama with OLLAMA_CONTEXT_LENGTH/);
+ assert.ok(!result.steps.some(step => step.name === 'speed'), 'nothing after a failed step');
+ assert.ok(lines.some(line => /FAIL context/.test(line)));
+});
+
+test('each engine is read where it reports its window: Ollama by name or :latest, LM Studio, llama.cpp, vLLM', async () => {
+ const run = (kind, model, options) => verifyEngine({ url: 'http://127.0.0.1:9/v1', model, kind, fetchImpl: engine({ bootFailures: 0, row: { id: model }, ...options }), log: quiet, sleep: instant });
+ const ollama = await run('ollama', 'qwen3', { reports: { '/api/ps': { models: [{ name: 'qwen3:latest', context_length: 131072 }] } } });
+ assert.equal(ollama.steps.find(step => step.name === 'context').contextTokens, 131072);
+ assert.equal(ollama.ok, true);
+ const lmStudio = await run('lm-studio', 'google/gemma-4-e2b', { reports: { '/api/v0/models': { data: [{ id: 'google/gemma-4-e2b', state: 'loaded', max_context_length: 131072, loaded_context_length: 4096 }] } } });
+ assert.match(lmStudio.steps.at(-1).note, /4096 tokens, under 65536: load it again with `lms load MODEL --context-length 65536`/);
+ const llamaCpp = await run('llama.cpp', 'widget', { reports: { '/props': { default_generation_settings: { n_ctx: 32768 } } } });
+ assert.match(llamaCpp.steps.at(-1).note, /32768 tokens, under 65536: .*--ctx-size ÷ --parallel/);
+ const vllm = await run('vllm', 'org/model', { row: { id: 'org/model', max_model_len: 65536 } });
+ assert.equal(vllm.ok, true);
+ assert.equal(vllm.steps.find(step => step.name === 'context').note, '65536 tokens');
+});
+
+test('an engine that does not report its window is a skip, said as one, never a pass', async () => {
+ const lines = [];
+ const result = await verifyEngine({ url: 'http://127.0.0.1:9/v1', model: 'widget', kind: 'mlx-lm', fetchImpl: engine({ bootFailures: 0 }), log: createLog(line => lines.push(line)), sleep: instant });
+ assert.equal(result.ok, true);
+ assert.deepEqual(result.steps.find(step => step.name === 'context'), { name: 'context', ok: true, skipped: true, note: 'mlx-lm does not report it' });
+ assert.ok(lines.some(line => /SKIP context — mlx-lm does not report/.test(line)));
+ assert.ok(!lines.some(line => /PASS context/.test(line)));
+});
+
+test('the grid-only check refuses a model served from this computer, which has an engine to check', () => {
+ const rows = [{ model: 'gemma-4-e2b', engine: 'external', node: 'Studio Mac' }, { model: 'Big-Model', node: 'GPU rig' }];
+ assert.match(relayOnlyRefusal(rows, 'GEMMA-4-E2B', 'Studio Mac'), /served from this computer \(Studio Mac\): check its engine with --at/);
+ assert.equal(relayOnlyRefusal(rows, 'Big-Model', 'Studio Mac'), null, 'an engine on another machine is what --grid alone is for');
+ assert.equal(relayOnlyRefusal(rows, 'gemma-4-e2b', undefined), null, 'no name for this computer: nothing to compare');
+ assert.equal(relayOnlyRefusal({ error: 'not a list' }, 'gemma-4-e2b', 'Studio Mac'), null);
+});
diff --git a/store/agents/autonomous-grid/toolchain/fleet.mjs b/store/agents/autonomous-grid/toolchain/fleet.mjs
index cc075e932..b727c988f 100644
--- a/store/agents/autonomous-grid/toolchain/fleet.mjs
+++ b/store/agents/autonomous-grid/toolchain/fleet.mjs
@@ -1,5 +1,5 @@
#!/usr/bin/env node
-import { createLog, verifyEngine, verifyModel, verifyRelay } from '../lib/verify.mjs';
+import { createLog, verifyEngine, verifyModel, verifyRelay, relayOnlyRefusal } from '../lib/verify.mjs';
import { join, resolve } from 'node:path';
import { atomicJson, DEFAULT_CONFIG, execute, gridJson, harnessNameFor, nameJoin, readConfig, runTracked } from '../lib/fleet.mjs';
import { createCollector } from '../lib/telemetry.mjs';
@@ -137,6 +137,12 @@ try {
}
const usage = 'Use: fleet verify --at http://HOST:PORT/v1 --model ID [--kind ENGINE] [--no-tools] [--grid GRID --alias NAME], or --grid GRID --alias NAME alone for an engine on another machine';
if (Boolean(options.grid) !== Boolean(options.alias) || (options.at ? !options.model : !options.grid)) throw new Error(usage);
+ if (!options.at) {
+ const config = await readConfig(workspace);
+ const listed = await gridJson({ id: 'local', transport: 'local' }, config.mode, ['models', options.grid], { timeoutMs: 30_000 });
+ const refusal = listed.ok ? relayOnlyRefusal(listed.value, options.alias, config.machines.find(m => m.transport === 'local')?.name) : null;
+ if (refusal) throw new Error(refusal);
+ }
const log = createLog();
const engine = options.at
? await verifyEngine({ url: options.at, model: options.model, kind: options.kind, tools: options.tools, log })
diff --git a/store/agents/autonomous-grid/toolchain/grid.sh b/store/agents/autonomous-grid/toolchain/grid.sh
index 94632bbf0..23f53b436 100755
--- a/store/agents/autonomous-grid/toolchain/grid.sh
+++ b/store/agents/autonomous-grid/toolchain/grid.sh
@@ -12,5 +12,5 @@ esac
if [ -x "$here/.venv/bin/grid" ]; then exec "$here/.venv/bin/grid" "$@"; fi
if command -v grid >/dev/null 2>&1; then exec grid "$@"; fi
if [ -x "${HOME}/.local/bin/grid" ]; then exec "${HOME}/.local/bin/grid" "$@"; fi
-echo 'Grid is missing. Run this harness’s toolchain/setup.sh.' >&2
+echo 'Grid is not installed on this computer. Run `harness grid setup`.' >&2
exit 127