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
The Store runs beside the viewers, with its installs and their progress (#879)
Deeb5bc83b919d0
diff --git a/cli/e2e/lean.e2e.ts b/cli/e2e/lean.e2e.tsindex e6162a3a7..e2a56e0b6 100644--- a/cli/e2e/lean.e2e.ts+++ b/cli/e2e/lean.e2e.ts@@ -21,7 +21,7 @@ import { readLeanBundle } from '../src/harnessd/leanBundle.js'type Engine = 'claude' | 'codex'/** The processes the master runs the services in, and the services, each on its own link to the core. */const PROCESSES = ['search', 'viewers', 'edge', 'teams']-const SERVICES = ['search', 'viewers', 'workspaces', 'usage', 'monitor', 'projects', 'teams']+const SERVICES = ['search', 'viewers', 'store', 'workspaces', 'usage', 'monitor', 'projects', 'teams']const commandOf = (pid: number): string => execFileSync('ps', ['-o', 'command=', '-p', String(pid)], { encoding: 'utf8' }).trim()const rssMiB = (pid: number): number => Number(execFileSync('ps', ['-o', 'rss=', '-p', String(pid)], { encoding: 'utf8' }).trim()) / 1024diff --git a/cli/e2e/services.e2e.ts b/cli/e2e/services.e2e.tsindex 259c12f95..89065f2ed 100644--- a/cli/e2e/services.e2e.ts+++ b/cli/e2e/services.e2e.ts@@ -53,14 +53,14 @@ const IN_THE_CORE = { HARNESSD_SERVICES: 'none' }const QUICK_TO_PARK = { HARNESSD_SERVICE_PARK_CRASHES: '3', HARNESSD_SERVICE_INITIAL_BACKOFF_MS: '200', HARNESSD_SERVICE_MAX_BACKOFF_MS: '1000' }/** The processes the services run in by default, and what makes every one of them fail as it starts. */const SERVICE_PROCESSES = ['search', 'viewers', 'edge', 'teams'] as const-const EVERY_PROCESS_FAILING = 'search,viewers,workspaces,usage,monitor,projects,teams'+const EVERY_PROCESS_FAILING = 'search,viewers,store,workspaces,usage,monitor,projects,teams'describe('a failing service never takes the core down', () => {let daemon: IsolatedDaemon | undefinedafterEach(async () => { await daemon?.close(); daemon = undefined })it('with every service failing to start, in its own process or in the core, the core starts, runs an agent through turns and a restart, and says each one is unavailable', async () => {- daemon = await IsolatedDaemon.create({ env: { HARNESSD_TEST_FAULTS: `${EVERY_PROCESS_FAILING},models,store`, ...QUICK_TO_PARK } })+ daemon = await IsolatedDaemon.create({ env: { HARNESSD_TEST_FAULTS: `${EVERY_PROCESS_FAILING},models`, ...QUICK_TO_PARK } })const d = daemononTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-120).join('\n')}`) })await d.start()@@ -68,14 +68,12 @@ describe('a failing service never takes the core down', () => {for (const service of SERVICE_PROCESSES) {await until(`the master to park ${service}`, () => d.log().includes(`[harnessd] service ${service} ended 3 times`) || null, 60_000, 250)}- for (const service of ['models', 'store']) {- expect(d.log()).toContain(`[services] ${service} did not start · injected fault: ${service} · the core runs without it`)- }+ expect(d.log()).toContain('[services] models did not start · injected fault: models · the core runs without it')const client = await LocalClient.connect(d)const agentId = await boundAgent(d, client, 'no-service-processes')await turn(client, agentId, 'first, with every service down')expect(await client.request('session_search', { query: 'first' })).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'search' })- expect(await client.request('dsh_list', {})).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'store' })+ expect(await client.request('dsh_list', {})).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'store', retryable: true })expect(await client.request('fs_list_dir', { path: d.projectsDir })).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'projects', retryable: true })expect(await client.request('machine_resources', {})).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'monitor', retryable: true })// With the monitor's process parked, the Monitor's list is still the list: its rows, without readings.@@ -238,8 +236,11 @@ describe('a failing service never takes the core down', () => {it('the store answers from its own service; one of its requests failing leaves its others and the core alone', async () => {daemon = await IsolatedDaemon.create({ env: { HARNESSD_TEST_FAULTS: 'store.dsh_list' } })- onTestFailed(() => { console.log(`---- daemon log\n${daemon?.log().split('\n').slice(-80).join('\n')}`) })- await daemon.start()+ const d = daemon+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-80).join('\n')}`) })+ await d.start()+ // In the viewers' process: asked before it has connected, it is answered SERVICE_UNAVAILABLE, retryable.+ await until('the store to connect', () => d.log().includes('[services] store connected') || null, 30_000, 200)const client = await LocalClient.connect(daemon)expect(await client.request('dsh_list', {})).toMatchObject({ error: 'SERVICE_FAILED', service: 'store' })// Its other requests are still the store's own answers, refusals included.@@ -352,7 +353,9 @@ describe('a failing service never takes the core down', () => {it('the store lists what is installed here and what the registry offers', async () => {daemon = await IsolatedDaemon.create()- await daemon.start()+ const d = daemon+ await d.start()+ await until('the store to connect', () => d.log().includes('[services] store connected') || null, 30_000, 200)const client = await LocalClient.connect(daemon)const listed = await client.request('dsh_list', {}, 60_000)expect(listed.error, JSON.stringify(listed).slice(0, 400)).toBeUndefined()diff --git a/cli/e2e/signedIn.e2e.ts b/cli/e2e/signedIn.e2e.tsindex 21f60db0b..6f2d72259 100644--- a/cli/e2e/signedIn.e2e.ts+++ b/cli/e2e/signedIn.e2e.ts@@ -14,7 +14,7 @@ import { FakeBackend, type FakeMachine } from './harness/fakeBackend.js'type Engine = 'claude' | 'codex'const MACHINE: FakeMachine = { machineId: 'c3'.repeat(16), computerId: 'e2e-computer-0000-0000-00000000000c', name: 'signed-in', token: 'e2e-token-signed-in' }-const SERVICES = ['search', 'viewers', 'workspaces', 'usage', 'monitor', 'projects', 'teams'] as const+const SERVICES = ['search', 'viewers', 'store', 'workspaces', 'usage', 'monitor', 'projects', 'teams'] as constconst row = async (client: LocalClient, agentId: string) =>((await client.request<{ agents: Array<Record<string, any>> }>('agents_list', { includeStopped: true }, 30_000)).agents)diff --git a/cli/e2e/storeProcess.e2e.ts b/cli/e2e/storeProcess.e2e.tsnew file mode 100644index 000000000..db0128154--- /dev/null+++ b/cli/e2e/storeProcess.e2e.ts@@ -0,0 +1,134 @@+/**+ * The Harness Store in its own process, beside the viewers (harnessd/services.ts `SERVICE_HOSTS`), on the+ * real daemon. The harnesses the release bundles are put in place by the Store's start; an install from a+ * repository runs there, its progress reaches the window as `dsh_install_status` through the core, and an+ * agent created on the harness the moment the install answers finds it installed, though the core keeps+ * the installed index for two seconds (dsh/installed.ts). Whatever happens to the process costs the Store+ * and the viewers alone: killed, a list asked meanwhile is answered SERVICE_UNAVAILABLE at once, agents go+ * on, and the master brings it back.+ */+import { execFileSync } from 'node:child_process'+import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'+import { join } from 'node:path'+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'+import { LocalClient, type Frame } from './harness/client.js'+import { IsolatedDaemon, until } from './harness/daemon.js'++const HARNESS = 'e2e/installed-here'+const FIRST = 'e2e/installed-first'++/** A harness in a git repository of its own, whose setup says a line: what `dsh_install` clones and sets up. */+function repository(d: IsolatedDaemon, id = HARNESS, name = 'Installed Here'): string {+ const dir = join(d.root, `repo-${id.replace('/', '-')}`)+ mkdirSync(dir, { recursive: true })+ writeFileSync(join(dir, 'harness.json'), JSON.stringify({ spec: 1, id, name, engine: 'claude', toolchain: { setup: './setup.sh' } }))+ writeFileSync(join(dir, 'setup.sh'), '#!/bin/sh\necho setting up\n', { mode: 0o755 })+ const git = (...args: string[]) => execFileSync('git', ['-C', dir, ...args], { env: { ...process.env, HOME: d.env.HOME, GIT_CONFIG_NOSYSTEM: '1' } })+ git('init', '-q', '-b', 'main')+ git('add', '.')+ git('-c', 'user.name=e2e', '-c', '[email protected]', 'commit', '-q', '-m', 'a harness')+ return dir+}++/** The process the Store runs in now, the viewers': the last one the master said it started. */+const viewersPid = (d: IsolatedDaemon): number | null => {+ const started = [...d.log().matchAll(/\[harnessd\] service viewers started \(pid (\d+)\)/g)]+ return started.length ? Number(started[started.length - 1][1]) : null+}+const connected = (d: IsolatedDaemon) => d.log().split('[services] store connected').length - 1+const row = async (client: LocalClient, agentId: string) =>+ ((await client.request<{ agents: Array<Record<string, any>> }>('agents_list', { includeStopped: true }, 30_000)).agents)+ .find((agent) => agent.id === agentId)+async function create(d: IsolatedDaemon, client: LocalClient, folder: string, dsh?: string): Promise<Record<string, any>> {+ const cwd = join(d.projectsDir, folder)+ mkdirSync(cwd, { recursive: true })+ const created = await client.request('agent_create', { engine: 'claude', cwd, bypassPermission: true, ...(dsh ? { dsh } : {}) }, 90_000)+ expect(created.error, JSON.stringify(created)).toBeUndefined()+ return until(`${folder} to bind`, async () => {+ const found = await row(client, created.agent.id)+ return found?.sessionId && found.status === 'active' ? found : null+ }, 60_000, 500)+}+async function turn(client: LocalClient, agentId: string, content: string): Promise<void> {+ const ended = client.next((frame: Frame) => frame.type === 'turn_ended' && frame.agentId === agentId, 45_000, `turn_ended (${content})`)+ client.send('message', { agentId, content })+ await ended+}++describe('the Store in its own process, beside the viewers', () => {+ let daemon: IsolatedDaemon | undefined+ afterEach(async () => { await daemon?.close(); daemon = undefined })+ const fresh = async () => {+ const d = await IsolatedDaemon.create({ env: { HARNESSD_SERVICE_INITIAL_BACKOFF_MS: '200', HARNESSD_SERVICE_MAX_BACKOFF_MS: '1000' } })+ daemon = d+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-150).join('\n')}`) })+ await d.start()+ await until('the Store to connect to the core', () => connected(d) >= 1 || null, 30_000, 200)+ return d+ }++ it('installs a harness there, says how it goes, and the agent created the moment it answers finds it', async () => {+ const d = await fresh()+ // The bundled harnesses, put in place by the Store's start (only a bundle carries them).+ if (process.env.E2E_BUNDLE_PATH) {+ await until('the bundled Model Manager in place', () => {+ try { return JSON.parse(readFileSync(join(d.env.DSH_DIR!, 'installed.json'), 'utf8')).some((record: { id: string }) => record.id === 'autonomous/autonomous-grid') || null } catch { return null }+ }, 30_000, 250)+ }+ const client = await LocalClient.connect(d)+ expect(await client.request('dsh_install', { url: repository(d, FIRST, 'Installed First') }, 180_000)).toMatchObject({ ok: true, id: FIRST })+ expect(await create(d, client, 'installed-first', FIRST)).toMatchObject({ dsh: FIRST, dshName: 'Installed First' })+ // The core keeps what is installed for two seconds (dsh/installed.ts), read whenever it creates,+ // forks, resumes or relaunches an agent on a harness, or the models read the Model Manager's. Asked to+ // create on the second harness all through its install (refused: not installed yet), it holds an index+ // without it when the install answers. Told the index changed, it reads it again.+ const cwd = join(d.projectsDir, 'installed-here')+ mkdirSync(cwd, { recursive: true })+ const early = () => client.request('agent_create', { engine: 'claude', cwd, bypassPermission: true, dsh: HARNESS }, 30_000)+ let warming = true+ const warmed = (async () => {+ while (warming) {+ expect(await early()).toMatchObject({ error: 'INVALID_DSH' })+ await new Promise((done) => setTimeout(done, 50))+ }+ })()+ const installing = client.request('dsh_install', { url: repository(d) }, 180_000)+ expect(await installing).toMatchObject({ ok: true, id: HARNESS })+ // At once, inside the two seconds the core keeps the installed index for.+ warming = false+ const created = await early()+ await warmed+ expect(created.error, JSON.stringify(created)).toBeUndefined()+ const agent = await until('the harness agent to bind', async () => {+ const found = await row(client, created.agent.id)+ return found?.sessionId && found.status === 'active' ? found : null+ }, 60_000, 500)+ expect(agent).toMatchObject({ dsh: HARNESS, dshName: 'Installed Here' })+ const statuses = client.frames.filter((frame) => frame.type === 'dsh_install_status').map((frame) => frame.payload ?? {})+ // Cloned before its manifest names it; set up and done under its id.+ expect(statuses.some((status) => status.phase === 'clone')).toBe(true)+ expect(statuses.filter((status) => status.id === HARNESS).map((status) => status.phase)).toEqual(expect.arrayContaining(['setup', 'done']))+ const catalog = (await client.request('dsh_list', {}, 60_000)).dsh as Array<Record<string, unknown>>+ expect(catalog.find((entry) => entry.id === HARNESS)).toMatchObject({ installed: true })+ await turn(client, agent.id, 'on a harness installed by the Store\'s process')+ expect(d.log()).toMatch(/\[services\] store connected/)+ expect(d.coresStarted()).toBe(1)+ client.close()+ })++ it('killed outright: asked meanwhile it says so at once, agents go on, and the master brings it back', async () => {+ const d = await fresh()+ const client = await LocalClient.connect(d)+ const agent = await create(d, client, 'store-killed')+ const pid = viewersPid(d)!+ process.kill(pid, 'SIGKILL')+ const listed = await client.request('dsh_list', {}, 30_000)+ if (listed.error) expect(listed).toMatchObject({ error: 'SERVICE_UNAVAILABLE', service: 'store', retryable: true })+ await turn(client, agent.id, 'while the Store was gone')+ await until('the Store to be back', () => connected(d) >= 2 || null, 30_000, 200)+ await until('the Store to list again', async () => Array.isArray((await client.request('dsh_list', {}, 60_000)).dsh) || null, 60_000, 500)+ expect(viewersPid(d)).not.toBe(pid)+ expect(d.coresStarted()).toBe(1)+ client.close()+ })+})diff --git a/cli/src/architecture.spec.ts b/cli/src/architecture.spec.tsindex cb759b88a..fee15f670 100644--- a/cli/src/architecture.spec.ts+++ b/cli/src/architecture.spec.ts@@ -177,12 +177,13 @@ const SERVICE_MAY_IMPORT: Record<string, string> = {** Then at 102,019 in 430 with #893's shell launch (step 5), from 106,006 in 451: search, the viewers, workspaces, usage, the* monitor and the project readers run in processes of their own, and their code is loaded into the- * core's only when they run there instead (services/inline.ts).+ * core's only when they run there instead (services/inline.ts). Then at 101,896 in 430 (step 6): the+ * Store runs beside the viewers.*///// Connected TUI shells added a literal-argv launch port and shell service (#893, 160 loaded lines); moving// the search filename out of its CLI command removed 188, so that change lowered the closure by 28.-const CORE_CLOSURE_BUDGET = 102_110+const CORE_CLOSURE_BUDGET = 101_990/** What is not the core's, by path: each goes to a service or its own process, in the plan's order. */const EDGE: RegExp[] = [@@ -199,6 +200,11 @@ const EDGE: RegExp[] = [* The edge files the core's process still loads, each with the step of the plan that takes it out. The* list only shrinks: an entry no longer reached fails the test, so remove it with the move that ends it.*/+/** The Wi-Fi device lists, installs and checks harnesses with the Store's code, in the core's process+ * (lib/autonomous-device/storeRuntime.ts). It reaches the Store through the Store's process once a port+ * can carry an install's progress back to it, or it leaves with the device (step 10). */+const STORE_BYPASS = 'step 10: the Wi-Fi device\'s own way into the Store, until it goes through the Store\'s process'+const CORE_MAY_REACH: Record<string, string> = {'cable/cableFleet.ts': 'step 9: the dial, in the devices process','cable/cableFrame.ts': 'step 9: the dial, in the devices process',@@ -223,15 +229,14 @@ const CORE_MAY_REACH: Record<string, string> = {'device/deviceFleet.ts': 'step 9: the fleet, beside the dial','device/deviceLink.ts': 'step 9: the fleet, beside the dial','device/machineList.ts': 'step 9: the dial, in the devices process',- 'dsh/builtins.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/catalog.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/install.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/lock.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/registry.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/service.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/update.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/updates.ts': 'step 6: the Store, in the viewers\' process',- 'dsh/wire.ts': 'step 6: the Store, in the viewers\' process',+ 'dsh/builtins.ts': 'the bundled harnesses are put in place by the core\'s start, which cli.js carries them for anyway; in the Store\'s lean process they cost a second copy (core/main.ts)',+ 'dsh/catalog.ts': STORE_BYPASS,+ 'dsh/install.ts': STORE_BYPASS,+ 'dsh/lock.ts': STORE_BYPASS,+ 'dsh/registry.ts': STORE_BYPASS,+ 'dsh/service.ts': STORE_BYPASS,+ 'dsh/update.ts': STORE_BYPASS,+ 'dsh/updates.ts': STORE_BYPASS,'lib/autonomous-device/direct.ts': 'step 10: the Wi-Fi device, into the devices process over the gateway','lib/autonomous-device/discovery.ts': 'step 10: the Wi-Fi device, into the devices process over the gateway','lib/autonomous-device/dump.ts': 'step 10: the Wi-Fi device, into the devices process over the gateway',@@ -291,7 +296,6 @@ const CORE_MAY_REACH: Record<string, string> = {'services/models.ts': 'step 7: models, in its own process','services/shell.ts': 'shell setup and launch receipts, in the edge host; only the argv launch stays in the core (#893)','services/requestErrors.ts': 'step 7: with the last service that uses it, models, out of the core\'s process',- 'services/store.ts': 'step 6: the Store, in the viewers\' process','sharing/collaboration.ts': 'step 8: the experimental host','sharing/crypto.ts': 'step 8: the experimental host','sharing/grants.ts': 'step 8: the experimental host',diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.tsindex ad01b2d0d..7d3c3a44a 100644--- a/cli/src/backendSocket.ts+++ b/cli/src/backendSocket.ts@@ -34,7 +34,7 @@ import { AuthSessionManager, AuthSessionError } from './lib/authSession.js'import { VERSION } from './version.js'import { registry, projectDisplayName, type RegisteredSession } from './lib/registry.js'import type { CloseAgentService } from './lib/closeAgentService.js'-import { isHiddenBuiltin } from './dsh/builtins.js'+import { isHiddenBuiltin } from './dsh/builtinIds.js'import { ENGINES, type AgentEngine } from './engines/types.js'import { gridCliPresence } from './lib/gridExec.js'import { GridFleetRpc, GRID_FLEET_PROTOCOL, GRID_FLEET_MAX_TIMEOUT_MS, parseGridFleetRequest } from './lib/gridFleetRpc.js'diff --git a/cli/src/core/AGENTS.md b/cli/src/core/AGENTS.mdindex cc46cf61e..fd0af4083 100644--- a/cli/src/core/AGENTS.md+++ b/cli/src/core/AGENTS.md@@ -38,5 +38,5 @@ questions. Everything else is a service ([../services/AGENTS.md](../services/AGEin this process. `serviceLinks.ts`: services in their own processes. `viewersLink.ts`: what the corekeeps of the viewers when they run in theirs. `workspacesLink.ts`: what the core tells workspaces intheirs. `teamsLink.ts`: every change to the teams' prompt scopes, kept until their process has it.- `monitorLink.ts`: the monitor's port, asked of its process. `agentQueries.ts`: what a service in its- own process may ask of the agents.+ `monitorLink.ts`: the monitor's port, asked of its process. `storeLink.ts`: what the Store in its+ process tells the core. `agentQueries.ts`: what a service in its own process may ask of the agents.diff --git a/cli/src/core/agents/create.ts b/cli/src/core/agents/create.tsindex 2a8be3e4f..43c19a1b7 100644--- a/cli/src/core/agents/create.ts+++ b/cli/src/core/agents/create.ts@@ -10,7 +10,7 @@ import { statSync } from 'node:fs'import { readdir } from 'node:fs/promises'import { join } from 'node:path'import type { BackendSocket } from '../../backendSocket.js'-import { MODEL_MANAGER_ID } from '../../dsh/builtins.js'+import { MODEL_MANAGER_ID } from '../../dsh/builtinIds.js'import { installedDsh } from '../../dsh/installed.js'import { harnessEnvToClear, type DshAccount } from '../../dsh/launch.js'import { dshPinnedPermissionMode } from '../../dsh/manifest.js'diff --git a/cli/src/core/main.ts b/cli/src/core/main.tsindex 8488f7639..bd29862fe 100644--- a/cli/src/core/main.ts+++ b/cli/src/core/main.ts@@ -74,7 +74,7 @@ import { externalProviders } from '../lib/sessionSearch/externals/index.js'import { type LaunchOverridesDeps } from '../lib/launchOverrides.js'import { buildHarnessSessionLabel } from '../lib/harnessSessionLabel.js'import { adoptLegacyHarnessSessions, listTmuxPanes } from '../lib/tmuxAgentDiscovery.js'-import { installedDsh } from '../dsh/installed.js'+import { installedDsh, invalidateInstalledDsh } from '../dsh/installed.js'import { prepareHarnessLaunch } from '../dsh/runtime.js'import { ApiConnections } from '../lib/apiConnections.js'import { rememberSavedApis } from '../lib/apiModels.js'@@ -138,10 +138,10 @@ import { createServiceLinks } from './serviceLinks.js'import { createViewersLink } from './viewersLink.js'import { createWorkspacesLink } from './workspacesLink.js'import { createMonitorLink } from './monitorLink.js'+import { createStoreLink } from './storeLink.js'import { answerAgentQuery } from './agentQueries.js'import { KNOWN_SERVICES, servicesTheMasterRuns } from '../harnessd/services.js'import { createTeamsLink } from './teamsLink.js'-import { startStore } from '../services/store.js'import { startModels } from '../services/models.js'import { startFleet } from '../services/fleet.js'import { CORE_EXIT_STOP, CORE_EXIT_UPDATE } from '../harnessd/protocol.js'@@ -817,6 +817,10 @@ async function runForeground(session: AuthSession | null): Promise<void> {}backend.viewerTargetProvider = (agentId) => ports.viewers?.forwardingUrl(agentId) ?? null+ // The harnesses the release bundles (the Model Manager, Devices, the Harness Monitor), before restore+ // relaunches an agent on one. Here and not in the Store's process: its lean bundle would carry a second+ // copy of their files (571 KB more cli.js) and the viewers' process held 12 MiB more at idle (measured+ // 2026-10-06), while cli.js, which the core runs, carries them anyway.ensureBundledCoreHarnesses()// Models: grid access, the model pictures on agents' frames, the keystroke prewarm, and the models@@ -1120,18 +1124,21 @@ async function runForeground(session: AuthSession | null): Promise<void> {const serviceToken = process.env.HARNESSD_SUPERVISED === '1' ? process.env.HARNESSD_SERVICE_TOKEN : undefinedconst outOfProcess = servicesTheMasterRuns(process.env, KNOWN_SERVICES)// The requests each service that can run in its own process answers, as core/api.ts declares them.- const requestsOf: Record<string, readonly string[]> = { search: SEARCH_REQUESTS, usage: USAGE_REQUESTS, monitor: MONITOR_REQUESTS, projects: PROJECTS_REQUESTS }+ const requestsOf: Record<string, readonly string[]> = { search: SEARCH_REQUESTS, store: STORE_REQUESTS, usage: USAGE_REQUESTS, monitor: MONITOR_REQUESTS, projects: PROJECTS_REQUESTS }// What the core keeps of the viewers in their own process, for the frames it builds (core/viewersLink.ts).const viewersLink = createViewersLink(coreApi, (frame, opts) => serviceLinks.notify('viewers', frame, opts))// How the core tells workspaces in their own process what to do, and answers them (core/workspacesLink.ts).const workspacesLink = createWorkspacesLink(coreApi, (frame) => serviceLinks.notify('workspaces', frame), forgetAgentProject)// Every change to the prompt scopes, kept until their own process has it, and each agent's scope (core/teamsLink.ts).const teamsLink = createTeamsLink({ notify: (frame) => serviceLinks.notify('teams', frame) })+ // What the Store in its own process tells the core: an install's progress, and that what is installed changed (core/storeLink.ts).+ const storeLink = createStoreLink(coreApi, invalidateInstalledDsh)const serviceLinks = createServiceLinks({token: serviceToken,owned: Object.fromEntries([...outOfProcess].map((name) => [name, requestsOf[name] ?? []])),answer: (service, query, payload) => service === 'viewers' ? viewersLink.answer(query, payload): service === 'workspaces' ? workspacesLink.answer(query, payload)+ : service === 'store' ? storeLink.answer(query, payload): service === 'teams' ? teamsLink.answer(query, payload) : answerAgentQuery(coreApi, query),})// A request a service declared goes to it: in its own process, or in this one (core/serviceHost.ts).@@ -1164,8 +1171,9 @@ async function runForeground(session: AuthSession | null): Promise<void> {// The prompt scopes, behind the service host's guard (a fault there costs no message its write) or in their own process.if (outOfProcess.has('teams')) ports.teams = backend.swarmPromptScopes = teamsLink.scopeselse serviceHost.start('teams', (_core, started) => { started.teams = backend.swarmPromptScopes }, coreApi, TEAMS_FALLBACKS)- // The harnesses installed here, and installing, updating and removing one (services/store.ts).- serviceHost.serve('store', startStore, coreApi, STORE_REQUESTS)+ // The harnesses installed here, and installing, updating and removing one (services/store.ts): in this+ // process, or beside the viewers in theirs (services/storeProcess.ts).+ if (!outOfProcess.has('store')) serviceHost.serve('store', inline!.startStore, coreApi, STORE_REQUESTS)// This machine's Claude and Codex rate limits, read with its own credentials (services/usage.ts): in this// process, or in the edge host (services/usageProcess.ts).if (!outOfProcess.has('usage')) serviceHost.serve('usage', inline!.startUsage, coreApi, USAGE_REQUESTS)diff --git a/cli/src/core/storeLink.spec.ts b/cli/src/core/storeLink.spec.tsnew file mode 100644index 000000000..41601a443--- /dev/null+++ b/cli/src/core/storeLink.spec.ts@@ -0,0 +1,23 @@+import { describe, expect, it, vi } from 'vitest'+import { fakeCore } from '../testing/fakeCore.js'+import { createStoreLink } from './storeLink.js'++describe('the Store in its own process, as the core hears it', () => {+ it('pushes an install\'s progress to the apps, and reads the installed index again when told it changed', () => {+ const core = fakeCore()+ const installed = vi.fn()+ const link = createStoreLink(core, installed)+ expect(link.answer('installStatus', { status: { id: 'acme/thing', phase: 'setup' } })).toEqual({ said: true })+ expect(core.clients.dshInstallStatus).toHaveBeenCalledWith({ id: 'acme/thing', phase: 'setup' })+ expect(link.answer('installed', {})).toEqual({ read: true })+ expect(installed).toHaveBeenCalledOnce()+ })++ it('pushes nothing that is not a status, and answers nothing else', () => {+ const core = fakeCore()+ const link = createStoreLink(core, vi.fn())+ for (const status of [undefined, 'clone', ['clone'], null]) expect(link.answer('installStatus', { status })).toEqual({ error: 'BAD_STATUS' })+ expect(core.clients.dshInstallStatus).not.toHaveBeenCalled()+ expect(link.answer('credentials', {})).toEqual({ error: 'UNKNOWN_QUERY' })+ })+})diff --git a/cli/src/core/storeLink.ts b/cli/src/core/storeLink.tsnew file mode 100644index 000000000..f27f1675c--- /dev/null+++ b/cli/src/core/storeLink.ts@@ -0,0 +1,28 @@+/**+ * The Harness Store in its own process, as the core hears it (beside the viewers; the process's side is+ * services/storeProcess.ts). The core asks the Store nothing: the apps' requests are routed to it. The+ * Store tells the core how an install is going, which the core pushes to the apps+ * (`CoreApi.clients.dshInstallStatus`), and that what is installed changed, so that the core reads the+ * installed index again rather than from its two-second cache (dsh/installed.ts): the create that follows+ * an install must find the harness just installed.+ */+import type { CoreApi } from './api.js'++export function createStoreLink(core: Pick<CoreApi, 'clients'>, installedChanged: () => void) {+ return {+ /** The core's answers to the Store's questions (core/serviceLinks.ts `answer`, for `store`). */+ answer(query: string, payload: Record<string, unknown>): Record<string, unknown> {+ if (query === 'installStatus') {+ const status = payload.status+ if (!status || typeof status !== 'object' || Array.isArray(status)) return { error: 'BAD_STATUS' }+ core.clients.dshInstallStatus(status as Record<string, unknown>)+ return { said: true }+ }+ if (query === 'installed') {+ installedChanged()+ return { read: true }+ }+ return { error: 'UNKNOWN_QUERY' }+ },+ }+}diff --git a/cli/src/dsh/builtinIds.ts b/cli/src/dsh/builtinIds.tsnew file mode 100644index 000000000..98c563363--- /dev/null+++ b/cli/src/dsh/builtinIds.ts@@ -0,0 +1,17 @@+/**+ * The release-bundled harnesses' ids and sources, and which of them the public picker leaves out: what+ * the core, the models service and the Store's list read of them. A module of their own, so that the+ * Store's process, which lists them (./wire.ts), does not load their installing (./builtins.ts) and the+ * bundled files it carries: about 1 MB of code in a lean process+ * (docs/design/2026-10-06-core-boundary-next.md, step 6).+ */+export const MODEL_MANAGER_ID = 'autonomous/autonomous-grid'+export const DEVICES_HARNESS_ID = 'autonomous/devices'+export const DEVICES_BUILTIN_SOURCE = 'builtin:devices'+export const HARNESS_MONITOR_ID = 'autonomous/harness-monitor'+export const HARNESS_MONITOR_BUILTIN_SOURCE = 'builtin:harness-monitor'++/** Built-ins opened through their own product entry points, absent from the public picker. */+export function isHiddenBuiltin(record: { source?: string | null }): boolean {+ return record.source === 'builtin:pair' || record.source === DEVICES_BUILTIN_SOURCE+}diff --git a/cli/src/dsh/builtins.ts b/cli/src/dsh/builtins.tsindex fc7d0eda8..cdd549a38 100644--- a/cli/src/dsh/builtins.ts+++ b/cli/src/dsh/builtins.ts@@ -1,6 +1,7 @@import { createHash, randomUUID } from 'node:crypto'import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs'import { dirname, join } from 'node:path'+import { DEVICES_BUILTIN_SOURCE, DEVICES_HARNESS_ID, HARNESS_MONITOR_BUILTIN_SOURCE, HARNESS_MONITOR_ID, MODEL_MANAGER_ID } from './builtinIds.js'import { dshRootDir, isBrokenDsh, readInstalledIndex, resolveInstalled, upsertInstalledRecord } from './installed.js'import { lockDsh } from './lock.js'import { readDshManifest } from './manifest.js'@@ -10,11 +11,9 @@ import { samePackageSource } from './updates.js'declare const __MODEL_MANAGER_BUNDLE__: stringdeclare const __DEVICES_BUNDLE__: stringdeclare const __HARNESS_MONITOR_BUNDLE__: string-export const MODEL_MANAGER_ID = 'autonomous/autonomous-grid'-export const DEVICES_HARNESS_ID = 'autonomous/devices'-export const DEVICES_BUILTIN_SOURCE = 'builtin:devices'-export const HARNESS_MONITOR_ID = 'autonomous/harness-monitor'-export const HARNESS_MONITOR_BUILTIN_SOURCE = 'builtin:harness-monitor'+export {+ DEVICES_BUILTIN_SOURCE, DEVICES_HARNESS_ID, HARNESS_MONITOR_BUILTIN_SOURCE, HARNESS_MONITOR_ID, isHiddenBuiltin, MODEL_MANAGER_ID,+} from './builtinIds.js'export type BundledFiles = Record<string, { content: string; executable: boolean; encoding?: 'base64' }>/** Install the trusted, release-bundled harness. Runtime provisioning remains@@ -56,11 +55,6 @@ export function ensureBundledCoreHarnesses(log: (line: string) => void = consolereturn ready}-/** Built-ins opened through their own product entry points, absent from the public picker. */-export function isHiddenBuiltin(record: { source?: string | null }): boolean {- return record.source === 'builtin:pair' || record.source === DEVICES_BUILTIN_SOURCE-}-/** Materialize `files` under `.bundled/<folder>/<revision>` and point the index at it. Idempotent per revision. */function installBuiltin(opts: { id: string; source: string; folder: string; files: BundledFiles; what: string; legacyPath?: string }): boolean {const { id, source, folder, files } = optsdiff --git a/cli/src/dsh/wire.ts b/cli/src/dsh/wire.tsindex 9e03e7c10..8ca44faed 100644--- a/cli/src/dsh/wire.ts+++ b/cli/src/dsh/wire.ts@@ -9,7 +9,7 @@ import { DSH_ID_RE, dshSupportedEngines, dshTier, viewerUse } from './manifest.jimport { registrySourceUrl, type DshRegistryEntry } from './registry.js'import { currentDshRegistry } from './catalog.js'import { dshUpdateInfo } from './updates.js'-import { isHiddenBuiltin } from './builtins.js'+import { isHiddenBuiltin } from './builtinIds.js'/*** `dsh_list`: the harnesses installed on this machine, then what the registry offers that is not.diff --git a/cli/src/harnessd/services.spec.ts b/cli/src/harnessd/services.spec.tsindex 5d885b454..291f1fd76 100644--- a/cli/src/harnessd/services.spec.ts+++ b/cli/src/harnessd/services.spec.ts@@ -328,14 +328,17 @@ describe('which services the core leaves to its master', () => {const supervised = { HARNESSD_SUPERVISED: '1', HARNESSD_SERVICE_TOKEN: 'token' }it('is what the master says it runs, told in a form a core from before the list reads too', () => {- const specs = serviceSpecs({ HARNESSD_SERVICES: 'search,viewers' }, SERVICE_HOSTS)- expect(serviceProcessesEnv(specs)).toEqual({ [SERVICE_PROCESSES_ENV]: 'search,viewers', HARNESSD_SERVICES: 'search,viewers' })+ const specs = serviceSpecs({ HARNESSD_SERVICES: 'search,workspaces' }, SERVICE_HOSTS)+ expect(serviceProcessesEnv(specs)).toEqual({ [SERVICE_PROCESSES_ENV]: 'search,workspaces', HARNESSD_SERVICES: 'search,workspaces' })+ // A process named as one of its services is named whole: the viewers' process runs the Store beside them.+ expect(serviceProcessesEnv(serviceSpecs({ HARNESSD_SERVICES: 'viewers' }, SERVICE_HOSTS))).toMatchObject({ [SERVICE_PROCESSES_ENV]: 'viewers,store' })+ expect(serviceProcessesEnv(serviceSpecs({ HARNESSD_SERVICES: 'store' }, SERVICE_HOSTS))).toMatchObject({ [SERVICE_PROCESSES_ENV]: 'store' })// By service, not by process: a core from before the edge host routes the services it knows of it.const hosted = serviceSpecs({ HARNESSD_SERVICES: 'edge' }, SERVICE_HOSTS)expect(serviceProcessesEnv(hosted)).toEqual({ [SERVICE_PROCESSES_ENV]: 'workspaces,usage,monitor,projects', HARNESSD_SERVICES: 'workspaces,usage,monitor,projects' })expect([...servicesTheMasterRuns({ ...supervised, ...serviceProcessesEnv(hosted) }, known)]).toEqual(['workspaces'])expect(serviceProcessesEnv([])).toEqual({ [SERVICE_PROCESSES_ENV]: '', HARNESSD_SERVICES: 'none' })- expect([...servicesTheMasterRuns({ ...supervised, ...serviceProcessesEnv(specs) }, known)]).toEqual(['search', 'viewers'])+ expect([...servicesTheMasterRuns({ ...supervised, ...serviceProcessesEnv(specs) }, known)]).toEqual(['search', 'workspaces'])expect([...servicesTheMasterRuns({ ...supervised, ...serviceProcessesEnv([]) }, known)]).toEqual([])// What the master says wins over whatever HARNESSD_SERVICES the core inherited; names it does not know are its own.expect([...servicesTheMasterRuns({ ...supervised, [SERVICE_PROCESSES_ENV]: ' teams, nothing ', HARNESSD_SERVICES: 'search' }, known)]).toEqual(['teams'])diff --git a/cli/src/harnessd/services.ts b/cli/src/harnessd/services.tsindex 626540a0f..b91126f08 100644--- a/cli/src/harnessd/services.ts+++ b/cli/src/harnessd/services.ts@@ -307,8 +307,9 @@ export type ServiceHostSpec = Omit<ServiceSpec, 'name'>export const SERVICE_HOSTS: Readonly<Record<string, ServiceHostSpec>> = {search: { services: ['search'], heapLimitMiB: 1_024, rssLimitMiB: 2_048 },// Its file watches on every harness's workspace; the viewer servers it starts are processes of their- // own, outside this budget.- viewers: { services: ['viewers'], heapLimitMiB: 512, rssLimitMiB: 1_024 },+ // own, outside this budget. The Store beside them: its installs run git and the harnesses' toolchains+ // in their own processes too, and take minutes, which is what it must not spend in the core.+ viewers: { services: ['viewers', 'store'], heapLimitMiB: 512, rssLimitMiB: 1_024 },// The git work (workspaces, the project readers) runs in git's own processes, and the monitor's// samples in ps's and ioreg's; what it holds is the agents the core sent it and one parsed sample.// The monitor parses up to 8 MB of ioreg output per Monitor poll on a Mac with a GPU, hence more@@ -377,8 +378,10 @@ export function servicesTheMasterRuns(env: NodeJS.ProcessEnv, known: readonly st* names a subset, by service (`search,workspaces`) or by process (`edge`, every service it hosts); `none`* (or empty) runs them all inside the core's process, for debugging or a quick way back. Isolation is* the point of the split (one service failing costs only its process), so it is the default, not an- * opt-in. Each process hosts the services named of its own, and is not started for none.- * `HARNESSD_SERVICE_HEAP_LIMIT_MIB` gives every one the same heap limit instead (tests, support).+ * opt-in. Each process hosts the services named of its own, and is not started for none. A process+ * named as one of its services is named whole: `viewers` runs the viewers' process, the Store beside+ * them, as it ran the viewers' before the Store joined it. `HARNESSD_SERVICE_HEAP_LIMIT_MIB` gives every+ * one the same heap limit instead (tests, support).*/export function serviceSpecs(env: NodeJS.ProcessEnv, hosts: Readonly<Record<string, ServiceHostSpec>>): ServiceSpec[] {const named = env.HARNESSD_SERVICES === undefined ? nulldiff --git a/cli/src/serviceProcess.ts b/cli/src/serviceProcess.tsindex 2b6afbc5b..8a4752193 100644--- a/cli/src/serviceProcess.ts+++ b/cli/src/serviceProcess.ts@@ -31,6 +31,7 @@ export const SERVICE_RUNNERS: ReadonlyMap<string, () => Promise<Runner>> = new M['usage', async () => (await import('./services/usageProcess.js')).runUsageService],['monitor', async () => (await import('./services/monitorProcess.js')).runMonitorService],['projects', async () => (await import('./services/projectsProcess.js')).runProjectsService],+ ['store', async () => (await import('./services/storeProcess.js')).runStoreService],['teams', async () => (await import('./services/teamsProcess.js')).runTeamsService],])diff --git a/cli/src/services/AGENTS.md b/cli/src/services/AGENTS.mdindex 996239454..f9bf34ab6 100644--- a/cli/src/services/AGENTS.md+++ b/cli/src/services/AGENTS.md@@ -43,12 +43,12 @@ let several people build features at once without touching the core or each otheA service that can crash natively, hang or leak should run in a process of its own, where it costs onlythat process. A process per risk, not per feature: search (native `node:sqlite`), the viewers (their-servers), the teams' prompt scopes, and the edge host, one process for the light services that only-answer requests (workspaces, usage, the monitor, the project readers). A fault in one of the edge-host's services can cost the others in it, never the core. Every service in `KNOWN_SERVICES` runs out-of the core's process by default, unless `HARNESSD_SERVICES` names a subset, by service-(`search,usage`) or by process (`edge`), and `HARNESSD_SERVICES=none` runs them all inside the core's-process (for debugging or a quick way back).+servers) with the Store (its minutes-long installs), the teams' prompt scopes, and the edge host, one+process for the light services that only answer requests (workspaces, usage, the monitor, the project+readers). A fault in one of the edge host's services can cost the others in it, never the core. Every+service in `KNOWN_SERVICES` runs out of the core's process by default, unless `HARNESSD_SERVICES` names+a subset, by service (`search,usage`) or by process (`edge`), and `HARNESSD_SERVICES=none` runs them+all inside the core's process (for debugging or a quick way back).- `src/harnessd/services.ts` runs it (`SERVICE_HOSTS`: each process, the services it hosts and itsmemory budget, one heartbeat for all of them). The core routes the requests it declared (itsdiff --git a/cli/src/services/inline.spec.ts b/cli/src/services/inline.spec.tsindex c66029e44..350868e79 100644--- a/cli/src/services/inline.spec.ts+++ b/cli/src/services/inline.spec.ts@@ -3,12 +3,13 @@ import * as inline from './inline.js'import { startMonitor } from './monitor.js'import { startProjects } from './projects.js'import { startSearch } from './search.js'+import { startStore } from './store.js'import { startUsage } from './usage.js'import { startViewers } from './viewers.js'import { startWorkspaces } from './workspaces.js'describe('the services the core runs in its own process only when they do not run in theirs', () => {it('are their own starts, unchanged: the same services either way', () => {- expect({ ...inline }).toEqual({ startMonitor, startProjects, startSearch, startUsage, startViewers, startWorkspaces })+ expect({ ...inline }).toEqual({ startMonitor, startProjects, startSearch, startStore, startUsage, startViewers, startWorkspaces })})})diff --git a/cli/src/services/inline.ts b/cli/src/services/inline.tsindex c19db8d63..93c73d047 100644--- a/cli/src/services/inline.ts+++ b/cli/src/services/inline.ts@@ -13,6 +13,7 @@export { startMonitor } from './monitor.js'export { startProjects } from './projects.js'export { startSearch } from './search.js'+export { startStore } from './store.js'export { startUsage } from './usage.js'export { startViewers } from './viewers.js'export { startWorkspaces } from './workspaces.js'diff --git a/cli/src/services/models.ts b/cli/src/services/models.tsindex 017ba0525..a5311b4b6 100644--- a/cli/src/services/models.ts+++ b/cli/src/services/models.ts@@ -11,7 +11,7 @@import { join } from 'node:path'import { baseNode } from '../harnessd/baseNode.js'import type { CoreApi, CorePorts, ModelsPort, ServiceRequest, ServiceRequests } from '../core/api.js'-import { MODEL_MANAGER_ID } from '../dsh/builtins.js'+import { MODEL_MANAGER_ID } from '../dsh/builtinIds.js'import { installedDsh } from '../dsh/installed.js'import { ApiConnections, apiConnectionsRequest } from '../lib/apiConnections.js'import { apiModelsRequest, rememberSavedApis } from '../lib/apiModels.js'diff --git a/cli/src/services/storeProcess.spec.ts b/cli/src/services/storeProcess.spec.tsnew file mode 100644index 000000000..0f0faed16--- /dev/null+++ b/cli/src/services/storeProcess.spec.ts@@ -0,0 +1,78 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { STORE_REQUESTS, type CoreApi } from '../core/api.js'+import { runServiceProcess, type CoreConnection, type ServiceProcessOptions } from './process.js'+import { runStoreService } from './storeProcess.js'++// The real default reaches a real socket and clones real repositories: never in a test.+vi.mock('./process.js', () => ({ runServiceProcess: vi.fn(() => ({ stop: vi.fn() })) }))++const ASKER = { local: true, owner: true }++describe('the Store in its own process', () => {+ afterEach(() => vi.clearAllMocks())++ const setup = () => {+ let options: ServiceProcessOptions | null = null+ let api: CoreApi | null = null+ /** What the core heard, in order: the install's progress, that the index changed, and the answer. */+ const heard: string[] = []+ const answers = {+ dsh_list: vi.fn(async () => { heard.push('listed'); return { dsh: [] } }),+ dsh_install: vi.fn(async () => {+ api!.clients.dshInstallStatus({ id: 'acme/thing', phase: 'clone' })+ heard.push('installed')+ return { ok: true, id: 'acme/thing' }+ }),+ dsh_update: vi.fn(async () => { heard.push('updated'); return { ok: true, id: 'acme/thing' } }),+ dsh_remove: vi.fn(() => { heard.push('removed'); return { ok: true, id: 'acme/thing' } }),+ }+ const service = { stop: vi.fn() }+ const handle = runStoreService({+ dataDir: '/data', socketPath: '/data/daemon-1.sock', machineId: 'm', token: 't',+ run: (given) => { options = given; return service },+ start: (core) => { api = core; return answers },+ })+ const query = vi.fn(async (name: string, payload?: Record<string, unknown>) => { heard.push(`told ${name}${payload?.status ? ` ${JSON.stringify(payload.status)}` : ''}`); return {} })+ const connect = () => options!.onConnected!({ query } satisfies CoreConnection)+ return { options: options!, api: api!, heard, query, connect, handle, service }+ }++ it('reaches the core as `store`, answering its four requests, holding no credential', async () => {+ const { options, api, handle, service } = setup()+ expect(handle).toBe(service)+ expect(options).toMatchObject({ name: 'store', socketPath: '/data/daemon-1.sock', machineId: 'm', token: 't' })+ expect(Object.keys(options.requests).sort()).toEqual([...STORE_REQUESTS].sort())+ await expect(api.account.accessToken()).rejects.toThrow('store holds no credential')+ })++ it('tells the core how an install goes, and that what is installed changed before it answers', async () => {+ const { options, heard, connect } = setup()+ connect()+ expect(await options.requests.dsh_install!({ id: 'acme/thing' }, ASKER)).toEqual({ ok: true, id: 'acme/thing' })+ await options.requests.dsh_update!({ id: 'acme/thing' }, ASKER)+ await options.requests.dsh_remove!({ id: 'acme/thing' }, ASKER)+ // A list changes nothing: the core is not told.+ await options.requests.dsh_list!({}, ASKER)+ expect(heard).toEqual([+ 'told installStatus {"id":"acme/thing","phase":"clone"}', 'installed', 'told installed',+ 'updated', 'told installed', 'removed', 'told installed', 'listed',+ ])+ })++ it('answers all the same with no core to tell, or one that cannot hear', async () => {+ const { options, heard, query, connect } = setup()+ expect(await options.requests.dsh_install!({ id: 'acme/thing' }, ASKER)).toEqual({ ok: true, id: 'acme/thing' })+ connect()+ query.mockRejectedValue(new Error('the core went away'))+ expect(await options.requests.dsh_install!({ id: 'acme/thing' }, ASKER)).toEqual({ ok: true, id: 'acme/thing' })+ await Promise.resolve()+ expect(heard).toEqual(['installed', 'installed'])+ })++ it('runs as a real service by default, on the Store\'s own requests', () => {+ runStoreService({ dataDir: '/data', socketPath: '/data/daemon-1.sock', machineId: 'm', token: 't' })+ const options = vi.mocked(runServiceProcess).mock.calls.at(-1)![0]+ expect(options.name).toBe('store')+ expect(Object.keys(options.requests).sort()).toEqual([...STORE_REQUESTS].sort())+ })+})diff --git a/cli/src/services/storeProcess.ts b/cli/src/services/storeProcess.tsnew file mode 100644index 000000000..4d882ef70--- /dev/null+++ b/cli/src/services/storeProcess.ts@@ -0,0 +1,58 @@+/**+ * The Harness Store in its own process (`harness __service store`), beside the viewers in theirs+ * (harnessd/services.ts `SERVICE_HOSTS`): the same requests as in the core's process (services/store.ts).+ * A clone, a toolchain's setup and its doctor take minutes and run their own processes: here they cost+ * the viewers' process at most, never the core. Installs are+ * locked across processes (dsh/lock.ts), so one the Wi-Fi device starts from the core's never runs beside+ * one started here.+ *+ * It tells the core two things (core/storeLink.ts):+ * - how an install or update is going (`installStatus`), which the core pushes to the apps as+ * `dsh_install_status`; one said while the core is away is lost, as a line of progress may be;+ * - that what is installed changed (`installed`), before it answers the request that changed it: the+ * core keeps the installed index for two seconds (dsh/installed.ts), and the create that follows an+ * install must find what was just installed.+ */+import type { CoreApi, ServiceRequest, ServiceRequests } from '../core/api.js'+import { runServiceProcess, type CoreConnection, type ServiceProcess } from './process.js'+import { processCoreApi } from './processCoreApi.js'+import { startStore } from './store.js'++export interface StoreServiceOptions {+ dataDir: string+ socketPath: string+ machineId: string+ token: string+ /** Swapped in tests for one that does not touch the real socket or process. */+ run?: typeof runServiceProcess+ /** Swapped in tests for a Store that clones and installs nothing. */+ start?: (core: CoreApi) => ServiceRequests+}++/** The requests that change what is installed here. */+const CHANGES = ['dsh_install', 'dsh_update', 'dsh_remove']++export function runStoreService(options: StoreServiceOptions): ServiceProcess {+ let core: CoreConnection | null = null+ const base = processCoreApi(options.dataDir, 'store')+ const api: CoreApi = {+ ...base,+ clients: { ...base.clients, dshInstallStatus: (status) => { void core?.query('installStatus', { status }).catch(() => {}) } },+ }+ const answers = (options.start ?? startStore)(api)+ /** Answered once the core has heard that what is installed changed: whatever it was, it may have. */+ const changing = (handle: ServiceRequest): ServiceRequest => async (payload, asker) => {+ const answer = await handle(payload, asker)+ await core?.query('installed').catch(() => {})+ return answer+ }+ const requests: ServiceRequests = Object.fromEntries(Object.entries(answers).map(([type, handle]) => [type, CHANGES.includes(type) ? changing(handle) : handle]))+ return (options.run ?? runServiceProcess)({+ name: 'store',+ socketPath: options.socketPath,+ machineId: options.machineId,+ token: options.token,+ requests,+ onConnected: (connection) => { core = connection },+ })+}