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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Swarm local models: offer shared models by choice, run yours beside shared APIs
bitcoinbuilder069d659e47cb
diff --git a/cli/src/core/api.ts b/cli/src/core/api.tsindex 25083d4a2..ec3647946 100644--- a/cli/src/core/api.ts+++ b/cli/src/core/api.ts@@ -722,7 +722,7 @@ export const OS_DEVICE_REQUESTS = ['os_device'] as constexport const MODELS_REQUESTS = ['grid_models_list', 'models_list','grid_fleet_models_list', 'grid_fleet_model_download', 'grid_fleet_model_start', 'grid_fleet_model_stop',- 'grid_fleet_run', 'grid_fleet_cancel', 'grid_swarm_sync', 'grid_swarm_api_share', 'grid_swarm_api_shares',+ 'grid_fleet_run', 'grid_fleet_cancel', 'grid_swarm_sync', 'grid_swarm_api_share', 'grid_swarm_api_shares', 'grid_swarm_offer', 'grid_swarm_offers','api_connections', 'codex_profiles_list', 'codex_profile_link',] as constdiff --git a/cli/src/lib/localModels.spec.ts b/cli/src/lib/localModels.spec.tsindex 765223a9a..7fd448f89 100644--- a/cli/src/lib/localModels.spec.ts+++ b/cli/src/lib/localModels.spec.ts@@ -280,6 +280,20 @@ describe('local model discovery and lifecycle', () => {expect((await service.list('home')).models[0].state).toBe('running')})+ it('lets a model start beside the APIs a Swarm shares, which run nothing here, and not beside another engine', async () => {+ const share = (port: number) => ({ endpoint_url: `http://127.0.0.1:${port}/${'a'.repeat(36)}/v1`, models: ['deepseek/x'] })+ await writeFile(join(records, 'shared.json'), JSON.stringify({ node_id: 'local-node', engines: [share(41001), share(41002)] }))+ await writeFile(join(records, 'shared.heartbeat'), '')+ await service.act('home', 'org/Small-GGUF', 'start'); await service.settled()+ expect((await service.list('home', true)).models.find(m => m.id === 'org/Small-GGUF')!.operation).toMatchObject({ phase: 'done' })+ await service.act('home', 'org/Small-GGUF', 'stop'); await service.settled()+ // One that is not a share's endpoint is an engine like any other.+ await writeFile(join(records, 'shared.json'), JSON.stringify({ node_id: 'local-node', engines: [share(41001), { endpoint_url: 'http://127.0.0.1:41003/v1', models: ['y'] }] }))+ await service.act('home', 'org/Small-GGUF', 'start'); await service.settled()+ expect((await service.list('home', true)).models.find(m => m.id === 'org/Small-GGUF')!.operation)+ .toMatchObject({ phase: 'failed', error: 'Open Model Manager to add a model alongside those already running.' })+ })+it('never offers Stop for an external endpoint or another machine', async () => {serving = trueawait writeFile(join(records, 'remote.json'), JSON.stringify({ node_id: 'local-node', engines: [{ endpoint_url: 'http://localhost:1234', models: ['Small-Q4.gguf'] }] }))diff --git a/cli/src/lib/localModels.ts b/cli/src/lib/localModels.tsindex a26929799..e58a5df42 100644--- a/cli/src/lib/localModels.ts+++ b/cli/src/lib/localModels.ts@@ -540,7 +540,10 @@ export class LocalModels {const pid = recordPid(record)const pidAlive = pid !== null && processExists(pid)const dead = pid !== null && !pidAlive- if ((specs.length || record.media) && !dead) blocker = 'Open Model Manager to add a model alongside those already running.'+ // An API a Swarm shares (`swarmApiShares.ts`) is joined as an engine too, but runs nothing here: it never stands in+ // a local model's way (owner, 2026-10-23: two shared APIs kept a model from running for the same Swarm).+ const sharedApis = specs.length > 0 && !record.media && specs.every(spec => SWARM_API_SHARE.test(str(spec.endpoint_url)))+ if ((specs.length || record.media) && !dead && !sharedApis) blocker = 'Open Model Manager to add a model alongside those already running.'for (const spec of specs) {if (spec.endpoint_url || spec.api_kind || !Array.isArray(spec.models) || spec.models.length !== 1) continueconst file = str(spec.models[0])@@ -1290,6 +1293,9 @@ function communityOf(grids: Record<string, any>[]): { osGrid?: string } {/** The one online node in [nodes] that is [instance]'s engine — its record's node id (or, with no ids,* its name) and every name it serves under; none while its heartbeat is stale or two nodes would match. */+/** The endpoint a Swarm's shared API is joined at (`swarmApiShares.ts`): this computer, a port, and its secret path. */+const SWARM_API_SHARE = /^http:\/\/127\.0\.0\.1:\d+\/[0-9a-f]{36}\/v1\/?$/+function nodeServing(nodes: Record<string, any>[], instance?: Owned): Record<string, any> | undefined {const matches = instance?.live ? nodes.filter(n => n.online === true &&(str(n.node_id || n.id) ? str(n.node_id || n.id) === instance.nodeId :diff --git a/cli/src/lib/swarmApiShares.spec.ts b/cli/src/lib/swarmApiShares.spec.tsindex 7244965d5..5b4e25656 100644--- a/cli/src/lib/swarmApiShares.spec.ts+++ b/cli/src/lib/swarmApiShares.spec.ts@@ -29,7 +29,7 @@ describe('an API shared with a Swarm', () => {expect(await f.shares.share(GRID, 'c1', 'deepseek/deepseek-chat')).toEqual({ ok: true })const args = f.exec.mock.calls[0]![0]expect(args).toEqual(['--remote', 'join', GRID, '--at', expect.stringMatching(/^http:\/\/127\.0\.0\.1:\d+\/[0-9a-f]{36}\/v1$/), '-m', 'deepseek/deepseek-chat',- '--advertise-as', 'deepseek/deepseek-chat', '--max-concurrency', '4', '--name', 'OpenRouter'])+ '--advertise-as', 'deepseek/deepseek-chat', '--max-concurrency', '4'])expect(args.join(' ')).not.toContain(KEY)expect(f.shares.list(GRID)).toEqual([{ grid: GRID, connectionId: 'c1', model: 'deepseek/deepseek-chat', name: 'OpenRouter' }])expect(f.shares.list('other')).toEqual([])diff --git a/cli/src/lib/swarmApiShares.ts b/cli/src/lib/swarmApiShares.tsindex cdc7942f1..daa4fe4de 100644--- a/cli/src/lib/swarmApiShares.ts+++ b/cli/src/lib/swarmApiShares.ts@@ -60,7 +60,9 @@ export class SwarmApiShares {}).catch(() => null)if (port === null) return { error: 'This computer could not open a local endpoint for the API.' }const joined = await this.deps.exec(['--remote', 'join', grid, '--at', `http://127.0.0.1:${port}/${token}/v1`, '-m', model,- '--advertise-as', model, '--max-concurrency', String(CONCURRENCY), '--name', access.connection.name]).catch(() => null)+ // No `--name`: on a remote grid it names this computer's node, not the engine, and an API's name there read as if+ // OpenRouter were the machine serving every model on it (2026-10-23).+ '--advertise-as', model, '--max-concurrency', String(CONCURRENCY)]).catch(() => null)if (joined?.code !== 'OK') { server.close(); return { error: joined ? said(joined) : 'grid could not be run on this computer.' } }this.running.set(key, { grid, connectionId, model, name: access.connection.name, server, alias: model })await this.note()diff --git a/cli/src/lib/swarmOffers.spec.ts b/cli/src/lib/swarmOffers.spec.tsnew file mode 100644index 000000000..b6ae03657--- /dev/null+++ b/cli/src/lib/swarmOffers.spec.ts@@ -0,0 +1,34 @@+import { describe, expect, it } from 'vitest'+import { mkdtemp, readFile, stat, writeFile } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { SwarmOffers } from './swarmOffers.js'++const GRID = 'swarm-0123456789ab'++describe('models shared with you, offered to a Swarm', () => {+ it('offers and stops by Swarm, grid and model, privately, and the same twice changes nothing', async () => {+ const file = join(await mkdtemp(join(tmpdir(), 'swarm-offers-')), 'offers.json')+ const offers = new SwarmOffers(file)+ expect(offers.list()).toEqual([])+ const muse = { grid: GRID, sharedGrid: 'team', model: 'muse' }+ expect(offers.set(muse, true)).toEqual([muse])+ expect(offers.set(muse, true)).toEqual([muse])+ offers.set({ grid: 'swarm-ffffffffffff', sharedGrid: 'team', model: 'muse' }, true)+ expect(offers.list(GRID)).toEqual([muse])+ expect(offers.list()).toHaveLength(2)+ expect((await stat(file)).mode & 0o777).toBe(0o600)+ expect(offers.set(muse, false)).toEqual([])+ expect(offers.list()).toEqual([{ grid: 'swarm-ffffffffffff', sharedGrid: 'team', model: 'muse' }])+ expect(JSON.parse(await readFile(file, 'utf8'))).toHaveLength(1)+ })+ it('reads junk and an unreadable file as nothing offered', async () => {+ const file = join(await mkdtemp(join(tmpdir(), 'swarm-offers-')), 'offers.json')+ await writeFile(file, JSON.stringify([null, { grid: GRID }, { grid: GRID, sharedGrid: 'team', model: 'x'.repeat(201) }, { grid: GRID, sharedGrid: 'team', model: 'm', extra: 1 }]))+ expect(new SwarmOffers(file).list()).toEqual([{ grid: GRID, sharedGrid: 'team', model: 'm' }])+ await writeFile(file, '{}')+ expect(new SwarmOffers(file).list()).toEqual([])+ await writeFile(file, 'not json')+ expect(new SwarmOffers(file).list()).toEqual([])+ })+})diff --git a/cli/src/lib/swarmOffers.ts b/cli/src/lib/swarmOffers.tsnew file mode 100644index 000000000..016d6837c--- /dev/null+++ b/cli/src/lib/swarmOffers.ts@@ -0,0 +1,35 @@+/**+ * The models shared with this computer's person that they offer to a Swarm (docs/plans/2026-10-23-swarm-local-models.md,+ * owner 2026-10-23): only those are in this machine's readings, so only those does the Lead start Builders on, and only+ * here, since only this computer's sign-in reaches the grid that serves them. Offering is a choice, as running a model or+ * sharing an API is: a model shared with someone is not offered to their Swarms by itself.+ */+import { readFileSync, writeFileSync } from 'node:fs'++export interface SwarmOffer { grid: string; sharedGrid: string; model: string }++const valid = (row: unknown): row is SwarmOffer => {+ const r = (row && typeof row === 'object' ? row : {}) as Record<string, unknown>+ return [r.grid, r.sharedGrid, r.model].every(v => typeof v === 'string' && v.length > 0 && v.length <= 200)+}++export class SwarmOffers {+ constructor(private readonly file: string) {}++ /** What is offered, to the Swarm whose grid is [grid] or to every Swarm. An unreadable file offers nothing. */+ list(grid?: string): SwarmOffer[] {+ let rows: unknown+ try { rows = JSON.parse(readFileSync(this.file, 'utf8')) } catch { return [] }+ return (Array.isArray(rows) ? rows : []).filter(valid).filter(o => !grid || o.grid === grid)+ .map(({ grid: g, sharedGrid, model }) => ({ grid: g, sharedGrid, model }))+ }++ /** Offers [model] of [sharedGrid] to the Swarm whose grid is [grid], or stops. Saying the same twice changes nothing. */+ set(offer: SwarmOffer, on: boolean): SwarmOffer[] {+ const same = (o: SwarmOffer) => o.grid === offer.grid && o.sharedGrid === offer.sharedGrid && o.model === offer.model+ const rest = this.list().filter(o => !same(o))+ const next = on ? [...rest, { grid: offer.grid, sharedGrid: offer.sharedGrid, model: offer.model }] : rest+ writeFileSync(this.file, JSON.stringify(next), { mode: 0o600 })+ return next.filter(o => o.grid === offer.grid)+ }+}diff --git a/cli/src/services/models.spec.ts b/cli/src/services/models.spec.tsindex 51ebef6b8..99c3058ae 100644--- a/cli/src/services/models.spec.ts+++ b/cli/src/services/models.spec.ts@@ -44,6 +44,11 @@ const apiShares = vi.hoisted(() => ({list: vi.fn((_grid?: string) => [{ grid: 'swarm-0123456789ab', connectionId: 'c1', model: 'm', name: 'OpenRouter' }]),restore: vi.fn(async (): Promise<void> => {}),}))+const swarmOffers = vi.hoisted(() => ({+ set: vi.fn((): unknown[] => [{ grid: 'swarm-0123456789ab', sharedGrid: 'team', model: 'muse' }]),+ list: vi.fn((_grid?: string) => [{ grid: 'swarm-0123456789ab', sharedGrid: 'team', model: 'muse' }]),+}))+vi.mock('../lib/swarmOffers.js', () => ({ SwarmOffers: vi.fn(function () { return swarmOffers }) }))vi.mock('../lib/swarmApiShares.js', () => ({ SwarmApiShares: vi.fn(function () { return apiShares }) }))vi.mock('../lib/swarmGrid.js', () => ({ syncSwarmGrid: vi.fn(async () => ({ ready: true, added: ['[email protected]'], removed: [] })) }))/** The Model Manager's grid commands: what each job was run as, and what it answers. */@@ -436,6 +441,27 @@ describe('the models service', () => {expect(gridExec).toHaveBeenLastCalledWith(['--remote', 'ls'])})+ it('offers a model shared with this computer\'s person to a Swarm, for them only, and lists what is offered', async () => {+ const { requests } = setup()+ const offer = requests.grid_swarm_offer!+ const ask = { grid: 'swarm-0123456789ab', sharedGrid: 'team', model: 'muse', action: 'start' }+ expect(await offer(ask, asker)).toEqual({ offers: [expect.objectContaining({ model: 'muse' })] })+ expect(swarmOffers.set).toHaveBeenLastCalledWith({ grid: 'swarm-0123456789ab', sharedGrid: 'team', model: 'muse' }, true)+ await offer({ ...ask, action: 'stop' }, asker)+ expect(swarmOffers.set).toHaveBeenLastCalledWith({ grid: 'swarm-0123456789ab', sharedGrid: 'team', model: 'muse' }, false)+ expect(await offer(ask, { ...asker, local: false })).toEqual({ error: 'OWNER_REQUIRED' })+ expect(await offer(ask, { ...asker, owner: false })).toEqual({ error: 'OWNER_REQUIRED' })+ for (const bad of [{ grid: 'team' }, { sharedGrid: '' }, { model: 'x'.repeat(201) }, { model: 7 }, { action: 'pause' }]) {+ expect(await offer({ ...ask, ...bad }, asker)).toEqual({ error: 'INVALID_REQUEST' })+ }+ swarmOffers.set.mockImplementationOnce(() => { throw new Error('read-only') })+ expect(await offer(ask, asker)).toEqual({ error: 'The offer could not be saved on this computer.' })+ expect(requests.grid_swarm_offers!({ grid: 'swarm-0123456789ab' }, asker)).toEqual({ offers: [expect.objectContaining({ model: 'muse' })] })+ expect(swarmOffers.list).toHaveBeenLastCalledWith('swarm-0123456789ab')+ requests.grid_swarm_offers!({}, asker)+ expect(swarmOffers.list).toHaveBeenLastCalledWith(undefined)+ })+it('refuses a command it cannot read, or one with no connection or request to belong to', async () => {const { requests } = setup()expect(await requests.grid_fleet_run!({ args: [] }, asker)).toEqual({ error: 'INVALID_GRID_COMMAND' })diff --git a/cli/src/services/models.ts b/cli/src/services/models.tsindex 26a22a5cb..46ea62603 100644--- a/cli/src/services/models.ts+++ b/cli/src/services/models.ts@@ -43,6 +43,7 @@ import { parseRuntimeProfile } from '../lib/runtimeProfileWire.js'import { ensureManagedGrid, startGridPinRecheck } from '../lib/runtimeInstall.js'import { syncSwarmGrid } from '../lib/swarmGrid.js'import { SwarmApiShares } from '../lib/swarmApiShares.js'+import { SwarmOffers } from '../lib/swarmOffers.js'import { internalOnThrow } from './requestErrors.js'/** The requests models answers for the apps, declared in core/api.ts for the core to route. */@@ -396,7 +397,8 @@ function modelsRequests(core: CoreApi, grid: GridSetUp, privateGridName: () => P* that harness's own `harness grid setup`; until then grid answers these in its own words. Their* handshake, `grid_fleet_capabilities`, is the socket's (core/api.ts `MODELS_REQUESTS`).*/-function gridCommands(grid: GridSetUp, dataDir: string, shares: SwarmApiShares = swarmApiShares(dataDir)): ServiceRequests {+function gridCommands(grid: GridSetUp, dataDir: string, shares: SwarmApiShares = swarmApiShares(dataDir),+ offers: SwarmOffers = new SwarmOffers(join(dataDir, 'swarm-offers.json'))): ServiceRequests {const fleet = new GridFleetRpc()return {// Pulls and builds can take minutes; the host answers when it is done and holds nothing else for it.@@ -434,6 +436,24 @@ function gridCommands(grid: GridSetUp, dataDir: string, shares: SwarmApiShares =grid_swarm_api_shares: (payload) => ({shares: shares.list(typeof payload.grid === 'string' ? payload.grid : undefined),}),+ // A model shared with this computer's person, offered to a Swarm or no longer (lib/swarmOffers.ts). Their choice+ // alone: Builders the Swarm starts here then run on someone else's model through their access.+ grid_swarm_offer: (payload, asker) => {+ if (!asker.local || !asker.owner) return { error: 'OWNER_REQUIRED' }+ const { grid: name, sharedGrid, model, action } = payload+ const text = (v: unknown) => typeof v === 'string' && v.length > 0 && v.length <= 200+ if (typeof name !== 'string' || !SWARM_GRID.test(name) || !text(sharedGrid) || !text(model) || (action !== 'start' && action !== 'stop')) {+ return { error: 'INVALID_REQUEST' }+ }+ try {+ return { offers: offers.set({ grid: name, sharedGrid: sharedGrid as string, model: model as string }, action === 'start') }+ } catch {+ return { error: 'The offer could not be saved on this computer.' }+ }+ },+ grid_swarm_offers: (payload) => ({+ offers: offers.list(typeof payload.grid === 'string' ? payload.grid : undefined),+ }),grid_fleet_cancel: (payload, asker) => ({cancelled: !!asker.connection && typeof payload.commandId === 'string' && fleet.cancel(asker.connection, payload.commandId),}),diff --git a/cli/src/superTabs/machines.spec.ts b/cli/src/superTabs/machines.spec.tsindex dd4b7a853..f19a4ec0c 100644--- a/cli/src/superTabs/machines.spec.ts+++ b/cli/src/superTabs/machines.spec.ts@@ -5,7 +5,7 @@ import { join } from 'node:path'import { afterEach, describe, expect, it, vi } from 'vitest'import type { RegisteredSession } from '../lib/registry.js'import { fakeCore } from '../testing/fakeCore.js'-import { apisOn, ContributedMachines, servedOn, sharedWith, swarmWorktreesFile } from './machines.js'+import { apisOn, ContributedMachines, offered, servedOn, sharedWith, swarmWorktreesFile } from './machines.js'import { SuperTabHostError } from './host.js'import { startAgent } from './start.js'@@ -187,7 +187,8 @@ describe('contributed machine executor', () => {const local = (await f.open.mock.results[0]!.value) as { request: ReturnType<typeof vi.fn> }local.request.mockImplementation((async (type: string) => type === 'grid_swarm_api_shares'? { shares: [{ grid: GRID, connectionId: 'c1', model: 'deepseek/deepseek-chat', name: 'OpenRouter' }] }- : type === 'grid_models_list' ? { grids: [{ name: 'team-grid', models: [{ id: 'qwen3-30b' }] }] } : { providers: [] }) as never)+ : type === 'grid_swarm_offers' ? { offers: [{ grid: GRID, sharedGrid: 'team-grid', model: 'qwen3-30b' }] }+ : type === 'grid_models_list' ? { grids: [{ name: 'team-grid', models: [{ id: 'qwen3-30b' }, { id: 'not-offered' }] }] } : { providers: [] }) as never)f.advance(); await f.machine.tick()expect(f.backend.mock.calls.filter(c => c[1] === 'POST').at(-1)![3]).toMatchObject({ localModels: [{ grid: GRID, model: 'deepseek/deepseek-chat', name: 'deepseek/deepseek-chat · OpenRouter', kind: 'api' },@@ -200,6 +201,11 @@ describe('contributed machine executor', () => {f.step(60_000); await f.machine.tick()expect(reads()).toBe(before + 1)})+ it('keeps of the models shared with its owner only those they offer', () => {+ const shared = [{ grid: 'team', model: 'a', kind: 'shared' as const }, { grid: 'team', model: 'b', kind: 'shared' as const }]+ expect(offered(shared, { offers: [{ sharedGrid: 'team', model: 'b' }] })).toEqual([shared[1]])+ expect(offered(shared, null)).toEqual([])+ })it('reads only live models of grids other than Swarms\', once each, and shared APIs of this Swarm alone', () => {const GRID = 'swarm-0123456789ab'expect(sharedWith(null, GRID)).toEqual([])diff --git a/cli/src/superTabs/machines.ts b/cli/src/superTabs/machines.tsindex 8748293cf..862ac94a5 100644--- a/cli/src/superTabs/machines.ts+++ b/cli/src/superTabs/machines.ts@@ -182,11 +182,12 @@ export class ContributedMachines {.filter(engine => supported(String(engine.engine)) && engine.installed === true).map(engine => String(engine.engine)): listedEngines.filter(supported)// Only while the owner has the Local models add-on on: the models this machine serves on the Swarm's grid (its own- // engines, the APIs it shares), then the ones it may use on other grids (shared with its owner, usable here alone).+ // engines, the APIs it shares), then the ones shared with its owner that they offer to this Swarm (usable here alone).const localModels = typeof row.localGrid === 'string' ? [...servedOn(await local.request('grid_fleet_models_list', {}, 20_000).catch(() => ({})), row.localGrid),...apisOn(await local.request('grid_swarm_api_shares', { grid: row.localGrid }, 10_000).catch(() => ({})), row.localGrid),- ...sharedWith(await this.gridModels(local), row.localGrid),+ ...offered(sharedWith(await this.gridModels(local), row.localGrid),+ await local.request('grid_swarm_offers', { grid: row.localGrid }, 10_000).catch(() => ({}))),].slice(0, MAX_LOCAL_MODELS) : nullconst observation = { generation: pool.generation, tools: reportedTools, ...(localModels ? { localModels } : {}),...(Object.keys(toolProbeErrors).length ? { toolProbeErrors } : {}),@@ -364,6 +365,13 @@ export function sharedWith(answer: unknown, swarmGrid: string): LocalModelReadinreturn out}+/** Of the models shared with this machine's owner, those a `grid_swarm_offers` answer says they offer to the Swarm+ * (`lib/swarmOffers.ts`, owner 2026-10-23: offering is a choice, not every model shared with someone). */+export function offered(shared: LocalModelReading[], answer: unknown): LocalModelReading[] {+ const offers = new Set(list(object(answer).offers).map(o => `${String(o.sharedGrid)}\0${String(o.model)}`))+ return shared.filter(m => offers.has(`${m.grid}\0${m.model}`))+}+/** The models a `grid_fleet_models_list` answer says this machine serves on [grid], by the name grid lists each under. */export function servedOn(answer: unknown, grid: string): LocalModelReading[] {const out: LocalModelReading[] = []diff --git a/desktop/lib/models/swarm_models_target.dart b/desktop/lib/models/swarm_models_target.dartindex 50fca7089..7a18a28ae 100644--- a/desktop/lib/models/swarm_models_target.dart+++ b/desktop/lib/models/swarm_models_target.dart@@ -23,6 +23,12 @@ class SwarmModelsTarget extends ChangeNotifier {/// The APIs this computer shares with the Swarm, by `connectionId` and model.Set<String> shares = {};++ /// The models shared with this person that this computer offers to the Swarm, by their grid and model.+ Set<String> offers = {};++ bool offered(String sharedGrid, String model) =>+ offers.contains(shareKey(sharedGrid, model));String? error;bool _disposed = false;@@ -33,6 +39,12 @@ class SwarmModelsTarget extends ChangeNotifier {shares.contains(shareKey(connectionId, model));Future<void> refresh() async {+ try {+ final answer = await app.swarmOffers(machineId, grid);+ offers = _keys(answer['offers'], 'sharedGrid');+ } catch (_) {+ // Unknown, not "none": keep what was last read.+ }try {final answer = await app.swarmApiShares(machineId, grid);shares = {@@ -49,6 +61,35 @@ class SwarmModelsTarget extends ChangeNotifier {if (!_disposed) notifyListeners();}+ static Set<String> _keys(Object? rows, String first) => {+ for (final row in rows is List ? rows : const [])+ if (row is Map && row[first] is String && row['model'] is String)+ shareKey(row[first] as String, row['model'] as String),+ };++ /// Offers [model], shared with this person on [sharedGrid], to the Swarm, or stops. Returns why it could not, or null.+ Future<String?> offer(+ String sharedGrid,+ String model, {+ required bool start,+ }) async {+ error = null;+ try {+ final answer = await app.swarmOffer(+ machineId,+ grid: grid,+ sharedGrid: sharedGrid,+ model: model,+ start: start,+ );+ error = answer['error'] as String?;+ } catch (_) {+ error = 'This computer could not be reached. Try again.';+ }+ await refresh();+ return error;+ }+/// Shares, or stops sharing, [model] of the saved API [connectionId]. Returns why it could not, or null.Future<String?> share(String connectionId,diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 787d170bb..ccb338eb2 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -11294,6 +11294,33 @@ class AppNotifier extends ChangeNotifier {timeout: const Duration(seconds: 12),);+ /// The models shared with this person that [machineId] offers to the Swarm whose grid is [grid] (CLI `lib/swarmOffers.ts`).+ Future<Map<String, dynamic>> swarmOffers(String machineId, String grid) =>+ _conn(machineId).request(+ 'grid_swarm_offers',+ payload: {'grid': grid},+ timeout: const Duration(seconds: 10),+ );++ /// Offers [model], shared with this person on [sharedGrid], to the Swarm whose grid is [grid], or stops: the Swarm's+ /// Lead may then start Builders on [machineId] on it.+ Future<Map<String, dynamic>> swarmOffer(+ String machineId, {+ required String grid,+ required String sharedGrid,+ required String model,+ required bool start,+ }) => _conn(machineId).request(+ 'grid_swarm_offer',+ payload: {+ 'grid': grid,+ 'sharedGrid': sharedGrid,+ 'model': model,+ 'action': start ? 'start' : 'stop',+ },+ timeout: const Duration(seconds: 10),+ );+/// The saved APIs [machineId] shares with the Swarm whose grid is [grid] (CLI `lib/swarmApiShares.ts`).Future<Map<String, dynamic>> swarmApiShares(String machineId, String grid) =>_conn(machineId).request(diff --git a/desktop/lib/state/swarm_search.dart b/desktop/lib/state/swarm_search.dartindex 2f7dec2eb..1324303e6 100644--- a/desktop/lib/state/swarm_search.dart+++ b/desktop/lib/state/swarm_search.dart@@ -325,7 +325,12 @@ class SwarmSearchController extends ChangeNotifier {if (entry.apiModel case final model?) {return swarm.shared(entry.api!.id, model.id) ? 'Shared' : null;}- if (local == null && entry.api == null) return 'Usable';+ if (entry.gridModel case GridModel(+ :final id,+ grid: final sharedGrid?,+ ) when local == null) {+ return swarm.offered(sharedGrid, id) ? 'Offered' : null;+ }}if (modelRowInUse(row)) return inUseWord;// An API's model says what Enter does on it — Use, when this pane can run on it, else nothing.@@ -516,6 +521,19 @@ class SwarmSearchController extends ChangeNotifier {run: () => swarm.share(api.id, model.id, start: !on),);}+ // A model shared with the person, on someone else's grid: offering it lets the Lead start Builders on their+ // machines on it (owner, 2026-10-23: a choice, as running a model or sharing an API is).+ if (entry.gridModel case GridModel(+ :final id,+ grid: final sharedGrid?,+ ) when entry.api == null) {+ final on = swarm.offered(sharedGrid, id);+ return (+ label: on ? 'Stop offering' : 'Offer to Swarm',+ command: 'picker.accept',+ run: () => swarm.offer(sharedGrid, id, start: !on),+ );+ }return null;}diff --git a/desktop/lib/widgets/swarm_resource_preview.dart b/desktop/lib/widgets/swarm_resource_preview.dartindex fa439bb75..eeecb052b 100644--- a/desktop/lib/widgets/swarm_resource_preview.dart+++ b/desktop/lib/widgets/swarm_resource_preview.dart@@ -1482,7 +1482,12 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {labelValue('Swarm',local == null- ? 'Usable by agents on your machines'+ ? swarm.offered(+ entry.gridModel?.grid ?? '',+ entry.gridModel?.id ?? '',+ )+ ? 'Offered: the PM can start Builders on your machines on it'+ : 'Offer to Swarm lets the PM start Builders on your machines on it': local.servedOn(swarm.grid)? 'Running for this Swarm': 'Run for Swarm lets agents on any machine in the Swarm use it',diff --git a/desktop/test/swarm_local_models_picker_test.dart b/desktop/test/swarm_local_models_picker_test.dartindex 0c05ac895..89d42765d 100644--- a/desktop/test/swarm_local_models_picker_test.dart+++ b/desktop/test/swarm_local_models_picker_test.dart@@ -40,6 +40,32 @@ class _SwarmApp extends ModelManagerTestApp {};}+ final offered = <({String sharedGrid, String model})>{};++ @override+ Future<Map<String, dynamic>> swarmOffers(+ String machineId,+ String grid,+ ) async => {+ 'offers': [+ for (final o in offered)+ {'grid': grid, 'sharedGrid': o.sharedGrid, 'model': o.model},+ ],+ };++ @override+ Future<Map<String, dynamic>> swarmOffer(+ String machineId, {+ required String grid,+ required String sharedGrid,+ required String model,+ required bool start,+ }) async {+ final key = (sharedGrid: sharedGrid, model: model);+ start ? offered.add(key) : offered.remove(key);+ return {'offers': <Object>[]};+ }+@overrideFuture<Map<String, dynamic>> swarmApiShare(String machineId, {@@ -146,12 +172,19 @@ void main() {.where((r) => search.modelSection(r) == ModelSearchSection.shared).map((r) => r.title);expect(shared, ['Shared Qwen · team.lan · Team']);- expect(- search.modelRowStatus(- search.rows.firstWhere((r) => r.title.startsWith('Shared Qwen')),- ),- 'Usable',- );+ // Not offered until the person offers it, and then stopped the same way.+ SwarmDestination qwen() =>+ search.rows.firstWhere((r) => r.title.startsWith('Shared Qwen'));+ expect(search.modelRowStatus(qwen()), isNull);+ final offer = search.swarmModelAction(qwen())!;+ expect(offer.label, 'Offer to Swarm');+ expect(await offer.run!(), isNull);+ expect(app.offered, {(sharedGrid: 'Team', model: 'Shared Qwen')});+ expect(search.modelRowStatus(qwen()), 'Offered');+ final stop = search.swarmModelAction(qwen())!;+ expect(stop.label, 'Stop offering');+ await stop.run!();+ expect(app.offered, isEmpty);},);diff --git a/docs/plans/2026-10-23-swarm-local-models.md b/docs/plans/2026-10-23-swarm-local-models.mdindex 1a8123834..9f0ea2e7c 100644--- a/docs/plans/2026-10-23-swarm-local-models.md+++ b/docs/plans/2026-10-23-swarm-local-models.md@@ -43,6 +43,9 @@ The ⌘I Models picker made for the Swarm (`SwarmModelsTarget` on `SwarmSearchCopath) that adds the key and forwards completions to the API; grid joins it with `--at`. Every Builder in the Swarm thenspends the sharer's key and credits, which the preview says. Shares end when the models service restarts (it takesstale ones off the grid at start).-- **Shared with you:** models other people share with you are usable by agents on *your* machines only (your machine's- grid sign-in reaches them). The backend admits such a start only on a machine whose fresh reading lists the model.+- **Shared with you:** a model other people share with you is offered to the Swarm only when you choose Offer to Swarm+ (owner, 2026-10-23); this computer keeps the list (`swarm-offers.json`) and reports only offered ones. Agents on *your*+ machines alone may use it (your machine's grid sign-in reaches it): the backend admits such a start only on a machine+ whose fresh reading lists the model.+- A shared API is never counted as a running local model, so your models can run for the Swarm beside shared APIs.- A click only selects a row; the preview's button (or Return) acts.