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
Main's gates green again: local models covered (#976), and presence keeps the gateway and socket rules (c39f32d8d) (#978)
Deed66d9c5b625c
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.tsindex 7622ac7e0..a27812378 100644--- a/cli/src/backendSocket.ts+++ b/cli/src/backendSocket.ts@@ -1,6 +1,7 @@import type { PurgeAgentService } from './lib/purgeAgentService.js'import { SHARE_REQUESTS, TEAMS_REQUESTS, type Asker, type LocalWindows, type WindowSurface, type BackendNotice, type GatewayEvents, type GatewayPort, type ModelsPort, type RemoteClient, type RemoteRole, type RemoteTransport } from './core/api.js'import { ServiceUnavailableError } from './core/serviceHost.js'+import { countWindows } from './lib/windowSurfaces.js'import type { ViewerStreams } from './core/viewerStreams.js'import type { ActivityFrame } from './lib/turnActivity.js'import { MonitorCompletions } from './lib/harnessMonitor.js'@@ -612,10 +613,7 @@ export class BackendSocket {}/** The windows attached now, per surface; tools are not windows. */- private localWindows(): LocalWindows {- const windows = this.localClients.size - this.toolClients.size- return { desktop: windows - this.tuiClients.size, tui: this.tuiClients.size }- }+ private localWindows(): LocalWindows { return countWindows(this.localClients.size, this.toolClients.size, this.tuiClients.size) }/** A loopback client that said it is a tool (`harness pair`, the MCP server), not a window. */isToolClient(connId: string): boolean { return this.toolClients.has(connId) }diff --git a/cli/src/core/api.ts b/cli/src/core/api.tsindex 8e8707ab9..1971e6736 100644--- a/cli/src/core/api.ts+++ b/cli/src/core/api.ts@@ -1014,20 +1014,11 @@ export type BackendNotice =| { type: 'machines_changed'; reason: string }| { type: 'device_keys_changed' }-/** What the core asks of the gateway: everything bound for a remote client, and the link's state. */-/** What a person has open on this computer: the desktop app, or `harness tui`. Each is its own presence. */-export type WindowSurface = 'desktop' | 'tui'-export type LocalWindows = Record<WindowSurface, number>-export const WINDOW_SURFACES: readonly WindowSurface[] = ['desktop', 'tui']-/** A surface off the core↔gateway pipe: anything but `tui` is the desktop app. */-export const windowSurfaceOf = (value: unknown): WindowSurface => (value === 'tui' ? 'tui' : 'desktop')-/** Window counts off the core↔gateway pipe; anything unreadable is none. */-export const localWindowsOf = (value: unknown): LocalWindows => {- const counts = (value ?? {}) as Partial<Record<WindowSurface, unknown>>- const count = (n: unknown): number => (typeof n === 'number' && Number.isFinite(n) && n > 0 ? Math.floor(n) : 0)- return { desktop: count(counts.desktop), tui: count(counts.tui) }-}+/** What a person has open on this computer, per surface (lib/windowSurfaces.ts). */+export type { LocalWindows, WindowSurface } from '../lib/windowSurfaces.js'+import type { LocalWindows, WindowSurface } from '../lib/windowSurfaces.js'+/** What the core asks of the gateway: everything bound for a remote client, and the link's state. */export interface GatewayPort {/** Dial the backend: this daemon is signed in. */connect(): voiddiff --git a/cli/src/gateway/gateway.ts b/cli/src/gateway/gateway.tsindex 278a818b0..ca948c49a 100644--- a/cli/src/gateway/gateway.ts+++ b/cli/src/gateway/gateway.ts@@ -14,7 +14,8 @@* E2EE_REQUIRED. backendSocket.spec.ts and gateway/gateway.spec.ts hold each of them.*/import { env } from '../config/env.js'-import { WINDOW_SURFACES, type GatewayEvents, type GatewayPort, type LocalWindows, type RemoteRole, type RemoteTransport, type WindowSurface } from '../core/api.js'+import type { GatewayEvents, GatewayPort, RemoteRole, RemoteTransport } from '../core/api.js'+import { WINDOW_SURFACES, type LocalWindows, type WindowSurface } from '../lib/windowSurfaces.js'import { deviceDump } from '../lib/autonomous-device/dump.js'import type { AuthSessionManager } from '../lib/authSession.js'import { shouldReplayCommander } from '../lib/commanderReplay.js'diff --git a/cli/src/gateway/gatewayProcess.ts b/cli/src/gateway/gatewayProcess.tsindex 339dd2b93..3ab8b1fad 100644--- a/cli/src/gateway/gatewayProcess.ts+++ b/cli/src/gateway/gatewayProcess.ts@@ -10,7 +10,8 @@* and the core going away stops it: a core's restart is the relay's, as it always was, so a remote client* that kept its socket opens a new session, as it did when both ran in one process.*/-import { localWindowsOf, windowSurfaceOf, type GatewayAccount, type GatewayEvents, type WindowRelaySession } from '../core/api.js'+import type { GatewayAccount, GatewayEvents, WindowRelaySession } from '../core/api.js'+import { localWindowsOf, windowSurfaceOf } from '../lib/windowSurfaces.js'import { decodeGatewayBinary, encodeGatewayBinary, GatewayBinary, GATEWAY_CALLS } from '../lib/gatewayWire.js'import { RelayConnectError } from '../lib/relayFrames.js'import { decodeTerminalLocal, encodeTerminalLocal } from '../lib/terminalBinary.js'diff --git a/cli/src/gateway/upstream.ts b/cli/src/gateway/upstream.tsindex 47d987105..78c4e52dc 100644--- a/cli/src/gateway/upstream.ts+++ b/cli/src/gateway/upstream.ts@@ -18,7 +18,7 @@import { WebSocket } from 'ws'import { hostname } from 'os'import { env } from '../config/env.js'-import { WINDOW_SURFACES, type LocalWindows, type WindowSurface } from '../core/api.js'+import { WINDOW_SURFACES, type LocalWindows, type WindowSurface } from '../lib/windowSurfaces.js'import { AuthSessionError, AuthSessionManager } from '../lib/authSession.js'import { BACKEND_IDLE_DEADLINE_MS, watchSocketLiveness, type LivenessWatch } from '../lib/wsLiveness.js'import { decodeTerminalHop, TerminalHopDirection } from '../lib/terminalBinary.js'diff --git a/cli/src/lib/localModels.spec.ts b/cli/src/lib/localModels.spec.tsindex 4689e5f74..c78dec1fa 100644--- a/cli/src/lib/localModels.spec.ts+++ b/cli/src/lib/localModels.spec.ts@@ -2375,5 +2375,69 @@ describe('Jev models: Get brings Grid\'s llama.cpp up to a build that serves theexpect(ops.stop).toHaveBeenCalledWith(expect.objectContaining({ modelId: TEV }))expect(await tev(models)).toEqual([])})++ it('is listed from the scan a daemon saved, before its first scan answers, with no quant when its app names none', async () => {+ const { quant: _quant, ...unquantized } = tev1+ await mkdir(stateDir, { recursive: true })+ await writeFile(join(stateDir, 'app-models.json'), JSON.stringify([unquantized]))+ // Its first scan answers later: the list before it is the saved one.+ const models = jevService({}, { appModels: () => new Promise<AppModel[]>(resolve => setTimeout(() => resolve([unquantized]), 50)) })+ const [row] = await tev(models)+ expect(row).toMatchObject({ name: 'tev1', kind: 'decision', app: 'Ollama', state: 'downloaded', canStart: true })+ expect(row).not.toHaveProperty('quant')+ })++ it('downloads nothing and starts nothing on a Get: it is here already, in its own app', async () => {+ const models = jevService({}, { appModels: async () => [tev1] })+ await models.act('home', TEV, 'download'); await models.settled()+ expect(ops.start).not.toHaveBeenCalled()+ expect(calls.some(args => args[0] === 'pull' || args[0] === 'engine' || args.includes('join'))).toBe(false)+ expect(await tev(models)).toEqual([expect.objectContaining({ state: 'downloaded', canStart: true, operation: expect.objectContaining({ phase: 'done' }) })])+ })++ it('keeps a row to stop one whose model a later scan no longer finds', async () => {+ let apps = [tev1]+ const models = jevService({}, { appModels: async () => apps })+ await models.act('home', TEV, 'start'); await models.settled()+ apps = []+ // A scan that no longer finds it: the record's own row, with nothing of the model's left to say but its name.+ await (models as any).scanApps()+ const [row] = await tev(models)+ expect(row).toMatchObject({ name: 'tev1', kind: 'decision', state: 'running', canStart: false, canStop: true })+ expect(row).not.toHaveProperty('sizeBytes')+ await models.act('home', TEV, 'stop'); await models.settled()+ expect(ops.stop).toHaveBeenCalledWith(expect.objectContaining({ modelId: TEV }))+ expect(await tev(models)).toEqual([])+ })+ })++ it('starts one again only when its engine is gone or its grid is read and does not list it', async () => {+ await engine('0.5.0-dev (build 11378, commit edd6e2bbd)')+ const models = jevService()+ const listed = inventory.getMockImplementation()!+ const start = async (answer?: unknown) => {+ if (answer !== undefined) inventory.mockImplementation(async () => answer as GridInventory)+ await models.act('home', LAYA, 'start'); await models.settled()+ inventory.mockImplementation(listed)+ }+ await start()+ expect(ops.start).toHaveBeenCalledOnce()+ // Served, or not known not to be: an unread grid, a sleeping one, and a node listing it by object, not by name.+ await start({ state: 'unknown', status: 'running', nodes: [] })+ await start({ state: 'asleep', status: 'asleep', nodes: [] })+ await start({ state: 'unknown', status: 'asleep', nodes: [] })+ await start({ state: 'awake', status: 'running', nodes: [{ node_id: 'local-node', online: true, models: [{ model: 'laya-english' }] }] })+ expect(ops.start).toHaveBeenCalledOnce()+ expect(ops.stop).not.toHaveBeenCalled()+ // A node whose models are not a list lists nothing: started again.+ await start({ state: 'awake', status: 'running', nodes: [{ node_id: 'local-node', online: true, models: 'laya-english' }] })+ expect(ops.stop).toHaveBeenCalledOnce()+ expect(ops.start).toHaveBeenCalledTimes(2)+ // Its engine gone: started again, whatever the grid says.+ up.delete(LAYA)+ await start()+ expect(ops.stop).toHaveBeenCalledTimes(2)+ expect(ops.start).toHaveBeenCalledTimes(3)+ expect(await laya(models)).toMatchObject({ state: 'running', operation: { phase: 'done' } })})})diff --git a/cli/src/lib/localModels.ts b/cli/src/lib/localModels.tsindex d71c7b9e5..a6d0c6c5b 100644--- a/cli/src/lib/localModels.ts+++ b/cli/src/lib/localModels.ts@@ -1155,7 +1155,7 @@ export class LocalModels {} else if (!record) {const jev = JEV_MODELS.find(m => m.id === operation.modelId)const model = jev ? await this.getJev(grid, jev, operation, change, must) : await this.appDecision(operation.modelId)- if (model && operation.action === 'start') await this.startDecision(grid, model, change, must)+ await this.startIfAsked(grid, model, operation, change, must)}operation.phase = 'done'delete operation.progress@@ -1163,6 +1163,15 @@ export class LocalModels {}/** [jev]'s weights, downloaded when they are not here; for a start, the model as Grid's llama.cpp runs it. */+ /** Starts [model] when the operation is a Start. Its own function: in line after the awaits above, which throw+ * for a model this computer cannot run, v8 counted the branch as taken -33 times and the coverage gate read it+ * as never taken. */+ private async startIfAsked(grid: string, model: AppModel | undefined, operation: ModelOperation,+ change: (stage: ModelOperation['stage']) => Promise<void>,+ must: (args: string[], message: string, output?: (chunk: string) => void) => Promise<void>): Promise<void> {+ if (model && operation.action === 'start') await this.startDecision(grid, model, change, must)+ }+private async getJev(grid: string, jev: JevModel, operation: ModelOperation,change: (stage: ModelOperation['stage']) => Promise<void>,must: (args: string[], message: string, output?: (chunk: string) => void) => Promise<void>): Promise<AppModel | undefined> {diff --git a/cli/src/lib/windowSurfaces.spec.ts b/cli/src/lib/windowSurfaces.spec.tsnew file mode 100644index 000000000..cf53958a4--- /dev/null+++ b/cli/src/lib/windowSurfaces.spec.ts@@ -0,0 +1,25 @@+import { describe, expect, it } from 'vitest'+import { countWindows, localWindowsOf, WINDOW_SURFACES, windowSurfaceOf } from './windowSurfaces.js'++describe('the windows a person has open, per surface', () => {+ it('reads a surface off the pipe: anything but tui is the desktop app', () => {+ expect(WINDOW_SURFACES).toEqual(['desktop', 'tui'])+ expect(windowSurfaceOf('tui')).toBe('tui')+ for (const value of ['desktop', 'web', undefined, null, 3, {}]) expect(windowSurfaceOf(value)).toBe('desktop')+ })++ it('reads window counts off the pipe, and anything unreadable as none', () => {+ expect(localWindowsOf({ desktop: 2, tui: 1 })).toEqual({ desktop: 2, tui: 1 })+ expect(localWindowsOf({ desktop: 2.7, tui: -1 })).toEqual({ desktop: 2, tui: 0 })+ expect(localWindowsOf({ desktop: 'two', tui: Number.NaN })).toEqual({ desktop: 0, tui: 0 })+ expect(localWindowsOf({ desktop: Number.POSITIVE_INFINITY })).toEqual({ desktop: 0, tui: 0 })+ expect(localWindowsOf(undefined)).toEqual({ desktop: 0, tui: 0 })+ expect(localWindowsOf(null)).toEqual({ desktop: 0, tui: 0 })+ })++ it('counts the loopback clients that are windows: tools are none, and tui windows are their own', () => {+ expect(countWindows(0, 0, 0)).toEqual({ desktop: 0, tui: 0 })+ expect(countWindows(5, 2, 1)).toEqual({ desktop: 2, tui: 1 })+ expect(countWindows(3, 0, 3)).toEqual({ desktop: 0, tui: 3 })+ })+})diff --git a/cli/src/lib/windowSurfaces.ts b/cli/src/lib/windowSurfaces.tsnew file mode 100644index 000000000..2d1619881--- /dev/null+++ b/cli/src/lib/windowSurfaces.ts@@ -0,0 +1,22 @@+/**+ * What a person has open on this computer: the desktop app, or `harness tui`. Each is its own presence.+ * Here, not in core/api.ts: the gateway reads these off its pipe to the core, and it may take only types+ * from the core's API (src/architecture.spec.ts), so that it runs in a process of its own without the core.+ */+export type WindowSurface = 'desktop' | 'tui'+export type LocalWindows = Record<WindowSurface, number>+export const WINDOW_SURFACES: readonly WindowSurface[] = ['desktop', 'tui']++/** A surface off the core↔gateway pipe: anything but `tui` is the desktop app. */+export const windowSurfaceOf = (value: unknown): WindowSurface => (value === 'tui' ? 'tui' : 'desktop')++/** Window counts off the core↔gateway pipe; anything unreadable is none. */+export const localWindowsOf = (value: unknown): LocalWindows => {+ const counts = (value ?? {}) as Partial<Record<WindowSurface, unknown>>+ const count = (n: unknown): number => (typeof n === 'number' && Number.isFinite(n) && n > 0 ? Math.floor(n) : 0)+ return { desktop: count(counts.desktop), tui: count(counts.tui) }+}++/** The windows attached now, per surface, from the loopback clients: a tool (`harness pair`, MCP) is no window. */+export const countWindows = (clients: number, tools: number, tuis: number): LocalWindows =>+ ({ desktop: clients - tools - tuis, tui: tuis })