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
Harness Team account joins and stays current with nothing run by hand
bitcoinbuilderebe99f71f10a
diff --git a/cli/src/lib/e2ee/deviceLogSyncer.spec.ts b/cli/src/lib/e2ee/deviceLogSyncer.spec.tsindex cd5b1bff9..803f53da4 100644--- a/cli/src/lib/e2ee/deviceLogSyncer.spec.ts+++ b/cli/src/lib/e2ee/deviceLogSyncer.spec.ts@@ -294,6 +294,38 @@ describe('DeviceLogSyncer', () => {expect(t.store.read().frozen).not.toBeNull()})+ it('heals a freeze from a page that claimed a head past its entries, once the backend serves them (#1789)', async () => {+ // A device registers between the backend's two reads: the page says the log reaches it, and carries no entry for it.+ t.backend.add(phone, 'viewer', '', 'phone')+ const real = t.backend.fetch.getMockImplementation()!+ t.backend.fetch.mockImplementationOnce(async (since: number) => ({ ...(await real(since))!, entries: [] }))+ await t.syncer.refresh()+ expect(t.store.read().frozen?.reason).toBe('invalid')+ expect(t.calls.adopt.mock.calls.flat(2).some((m: { pub: string }) => m.pub === phone.pub)).toBe(false)+ // The fixed backend serves the entry: it continues the chain this machine verified, so the freeze is over.+ await t.syncer.refresh()+ expect(t.store.read().frozen).toBeNull()+ expect(t.store.read().state?.head).toEqual(t.backend.state.head)+ expect(t.calls.adopt.mock.calls.flat(2).some((m: { pub: string }) => m.pub === phone.pub)).toBe(true)+ })++ it('stays frozen as invalid while what the backend serves does not check out', async () => {+ t.backend.add(phone, 'viewer', '', 'phone')+ const real = t.backend.fetch.getMockImplementation()!+ t.backend.fetch.mockImplementationOnce(async (since: number) => ({ ...(await real(since))!, entries: [] }))+ await t.syncer.refresh()+ expect(t.store.read().frozen?.reason).toBe('invalid')+ // Entries that do not continue the verified chain: a forged log ahead of it.+ const forged = new FakeBackend()+ forged.add(evil, 'viewer', '', 'evil')+ forged.add(phone, 'viewer', '', 'phone')+ forged.add(box2, 'machine', MID2, 'box2')+ t.backend.lie = forged.entries+ await t.syncer.refresh()+ expect(t.store.read().frozen?.reason).toBe('invalid')+ expect(t.calls.adopt.mock.calls.flat(2).some((m: { pub: string }) => m.pub === evil.pub)).toBe(false)+ })+it('shows what trusting the log again changes, and does it only when confirmed', async () => {t.backend.lie = t.backend.entries.slice(0, 1)await t.syncer.refresh()diff --git a/cli/src/lib/e2ee/deviceLogSyncer.ts b/cli/src/lib/e2ee/deviceLogSyncer.tsindex 913c76515..6c9b93758 100644--- a/cli/src/lib/e2ee/deviceLogSyncer.ts+++ b/cli/src/lib/e2ee/deviceLogSyncer.ts@@ -593,7 +593,13 @@ export class DeviceLogSyncer {}const current = this.deps.store.read()const state = current.state!- if (current.frozen) { this.looseRemovals(got.entries); return }+ // A log frozen as `invalid` from a page that claimed a head past the entries it carried heals by itself once the+ // backend serves them: the backend did that whenever a device registered between its two reads, and froze every+ // device that read at that moment until someone ran `harness devices rebaseline` (#1789, fixed 2026-10-27; a Mac+ // frozen on 10-24 could never link its Harness Team account). The entries must continue the chain this machine+ // verified and check out one by one (`accept`), or it stays frozen. A rollback or a fork never heals on its own.+ const heals = current.frozen?.reason === 'invalid' && got.head.seq > state.head.seq && got.entries.length > 0+ if (current.frozen && !heals) { this.looseRemovals(got.entries); return }if (got.head.seq < state.head.seq) { this.freeze('rollback'); return }if (got.head.seq === state.head.seq) {if (got.head.hash !== state.head.hash) this.freeze('fork')@@ -601,6 +607,7 @@ export class DeviceLogSyncer {}if (!got.entries.length) { this.freeze('invalid'); return }if (!this.accept(got.entries, bootstrap)) return+ if (heals) this.deps.log?.('[devlog] the device list checks out again: no longer frozen')if (this.deps.store.read().state!.head.seq >= got.head.seq) return}}diff --git a/cli/src/lib/selfUpdate.spec.ts b/cli/src/lib/selfUpdate.spec.tsindex 25042482e..babeb2b5b 100644--- a/cli/src/lib/selfUpdate.spec.ts+++ b/cli/src/lib/selfUpdate.spec.ts@@ -77,6 +77,11 @@ describe('shouldAutoUpdate', () => {expect(shouldAutoUpdate('9.9.9', '0.1.56-dev.a1b2c3d.dirty')).toBe(false)})+ it('takes releases over a local build in the Harness Team account, which nobody develops in', () => {+ expect(shouldAutoUpdate('0.1.57', '0.1.56-dev.a1b2c3d.dirty', true)).toBe(true)+ expect(shouldAutoUpdate('0.1.56', '0.1.56-dev.a1b2c3d', true)).toBe(false)+ })+it('leaves a released install on the release train', () => {expect(shouldAutoUpdate('0.1.57', '0.1.56')).toBe(true)expect(shouldAutoUpdate('0.1.56', '0.1.56')).toBe(false)diff --git a/cli/src/lib/selfUpdate.ts b/cli/src/lib/selfUpdate.tsindex 84777e397..e33044b8a 100644--- a/cli/src/lib/selfUpdate.ts+++ b/cli/src/lib/selfUpdate.ts@@ -149,8 +149,8 @@ export function isLocalDevBuild(version: string): boolean {* worth that — a developer who wants the release can ask for it (`harness update --force`) and a* release install, which is every user's, still updates exactly as before.*/-export function shouldAutoUpdate(candidate: string, current: string): boolean {- if (isLocalDevBuild(current)) return false+export function shouldAutoUpdate(candidate: string, current: string, followReleases = false): boolean {+ if (isLocalDevBuild(current) && !followReleases) return falsereturn semverGt(candidate, current)}@@ -632,6 +632,12 @@ export function startSelfUpdater(opts: {* itself (HARNESSD_JUDGES_SUPERSEDED).*/stageWhileJudged?: boolean+ /**+ * Take releases over a local build too. The Harness Team account's daemon: setup copies its owner's CLI into it, and+ * an owner on a local build left it on that build for good, without what came after it (2026-10-27: no subscription+ * relay, so its engines read signed out and the Lead routed nothing there). Nobody develops in the team account.+ */+ followReleases?: boolean/** Whose layout `dir` has; this process's when left out. */platform?: NodeJS.Platform/**@@ -711,7 +717,7 @@ export function startSelfUpdater(opts: {// review). What is installed is the build `cli\current` names; this process's own version only when the// pointer cannot be read. The dev-build rule then applies to that build, the one a developer installed.const installed = pointed() ?? opts.currentVersion- if (!shouldAutoUpdate(entry.version, installed)) return+ if (!shouldAutoUpdate(entry.version, installed, opts.followReleases)) returnconst unremembered = settleRolledBack(opts.dir, platform)if (unremembered === entry.version || rejectedVersions(opts.dir).includes(entry.version)) {if (toldRejected !== entry.version) console.log(`[update] ${entry.version} was rolled back on this machine — waiting for a newer build (\`harness update\` installs it anyway)`)@@ -773,7 +779,7 @@ export function startSelfUpdater(opts: {// above, and the installer or another process may have put a newer build in meanwhile. The next// check's gate then refuses it, so this is said once.const pointedNow = pointed()- if (pointedNow !== null && !shouldAutoUpdate(ready.version, pointedNow)) {+ if (pointedNow !== null && !shouldAutoUpdate(ready.version, pointedNow, opts.followReleases)) {console.log(`[update] ${ready.version} is no longer an update: the installed build is now ${pointedNow}. Nothing was staged.`)return}diff --git a/cli/src/services/updaterProcess.spec.ts b/cli/src/services/updaterProcess.spec.tsindex 1f88afdde..41ea13c26 100644--- a/cli/src/services/updaterProcess.spec.ts+++ b/cli/src/services/updaterProcess.spec.ts@@ -7,7 +7,8 @@ import type { startSelfUpdater } from '../lib/selfUpdate.js'import type { startPtyUpdater } from '../lib/windows/ptyUpdate.js'import type { startTuiUpdater } from '../tui/update.js'import { VERSION } from '../version.js'-import { processUpdaterDeps, runUpdaterService, type UpdaterServiceDeps } from './updaterProcess.js'+import { inTeamAccount, processUpdaterDeps, runUpdaterService, type UpdaterServiceDeps } from './updaterProcess.js'+import type { readTeamConfig } from '../team/config.js'// A lock someone else holds a moment: what the updater says while it waits for it.const locked = vi.hoisted(() => [] as string[])@@ -107,6 +108,21 @@ describe('the updater in its own process', () => {return { deps, windows, calls, told, ready, cli: () => cli!, hn: () => hn!, pty: () => pty, sent: () => sent! }}+ it('follows releases in the Harness Team account, and only there', () => {+ const team = make()+ runUpdaterService(undefined, { ...team.deps, inTeamAccount: () => true }).stop()+ expect(team.cli()).toMatchObject({ followReleases: true })+ const owner = make()+ runUpdaterService(undefined, { ...owner.deps, inTeamAccount: () => false }).stop()+ expect(owner.cli()).not.toHaveProperty('followReleases')+ // The account the root-owned team config names, and no other; an account whose name cannot be read is not it.+ const named = { user: 'harnessteam' } as ReturnType<typeof readTeamConfig>+ expect(inTeamAccount(() => named, () => 'harnessteam')).toBe(true)+ expect(inTeamAccount(() => named, () => 'owner')).toBe(false)+ expect(inTeamAccount(() => null, () => 'harnessteam')).toBe(false)+ expect(inTeamAccount(() => named, () => { throw new Error('no passwd entry') })).toBe(false)+ })+it('checks for this build\'s successor, and hn\'s, on the installed copy, and stops both', () => {const m = make()const service = runUpdaterService(undefined, m.deps)diff --git a/cli/src/services/updaterProcess.ts b/cli/src/services/updaterProcess.tsindex 73a90fd61..8478fcafe 100644--- a/cli/src/services/updaterProcess.ts+++ b/cli/src/services/updaterProcess.ts@@ -20,7 +20,9 @@* if that build then fails to stage, the host is taken back out and nothing is told (lib/windows/ptyUpdate.ts* `takeBackPty`).*/+import { userInfo } from 'node:os'import { env } from '../config/env.js'+import { readTeamConfig } from '../team/config.js'import { SERVICE_EXIT_RESTART, type StagedUpdate, type UpdaterMessage } from '../harnessd/protocol.js'import { describeSpawnLockOwner, withSpawnLock } from '../lib/daemonSpawnLock.js'import { DOWNLOAD_LIMITS, downloadVerified, isLocalDevBuild, retireCliVersions, startSelfUpdater } from '../lib/selfUpdate.js'@@ -54,6 +56,8 @@ export interface UpdaterServiceDeps {/** Windows: the protocol of the installed host, which a CLI build must not need more than (lib/selfUpdate.ts* `installedPtyProtocol`). Left out elsewhere. */installedPtyProtocol?: () => number | null+ /** Whether this daemon is a Mac's Harness Team account (team/config.ts names its user); real by default. */+ inTeamAccount?: () => boolean}/** [cliDir]: the CLI folder the retirement looks at, this user's own unless a test names one of its own. */@@ -116,6 +120,8 @@ export function runUpdaterService(_options?: unknown, deps: UpdaterServiceDeps =let ptyTaken: StagedHost | null = nullconst cli = deps.startCli({currentVersion: VERSION,+ // The Harness Team account takes releases even over the local build setup may have copied into it (selfUpdate.ts).+ ...((deps.inTeamAccount ?? inTeamAccount)() ? { followReleases: true } : {}),url: env.ADAPTER_UPDATE_URL,key: env.ADAPTER_UPDATE_KEY,dir: env.ADAPTER_CLI_DIR,@@ -204,3 +210,9 @@ function startPty(deps: { prepare: (entry, runtimeDir, verified) => preparePtyPayload(entry, runtimeDir, { download: (ref) => downloadVerified(ref, limits) }, verified) },})}++/** This process runs as the Harness Team account its Mac's root-owned config names. An account whose name cannot be read+ * is not it. */+export function inTeamAccount(config = readTeamConfig, user = () => userInfo().username): boolean {+ try { return config()?.user === user() } catch { return false }+}diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex 2e460f649..af25f99ad 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -16,8 +16,11 @@ import { cardId, SwarmCards } from './cards.js'import { GitHubTokenRefresher, githubToken } from './github.js'import { teamEngineReporter, type TeamEngineReporter } from '../team/engines.js'import { AUTO_SETUP_REASONS, realTeamAutoSetup, type AutoSetupReason, type TeamAutoSetup } from '../team/autoSetup.js'+import { openDaemon } from '../agentClient/daemon.js'import { readTeamConfig } from '../team/config.js'import { realTeamRelayPublisher, type TeamRelayPublisher } from '../team/relay.js'+import { readLastTry, refreshCreationId, refreshTeamAccount, teamRefreshFile, writeLastTry, type TeamRefreshDeps } from '../team/refresh.js'+import { readTeamStatus } from '../team/privacy.js'import { createOwnerSubscriptions } from '../lib/ownerSubscriptions.js'import { startSubscriptionRelay } from '../lib/subscriptionRelay.js'@@ -228,7 +231,9 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =// relay of its own (team/relay.ts). Kept through a lost backend connection, which running agents do not need.const relay = (options.teamRelay ?? (() => realTeamRelayPublisher(() => startSubscriptionRelay({ owner: createOwnerSubscriptions(), log: line => console.log(`[team] relay · ${line}`) }),- () => readTeamConfig(), options.team ?? (() => readAuthSession()?.kind === 'team'), line => console.log(`[team] ${line}`))))()+ () => readTeamConfig(), options.team ?? (() => readAuthSession()?.kind === 'team'), line => console.log(`[team] ${line}`),+ // A team account still on a build that cannot use the relay is updated from here (team/refresh.ts).+ (publishedAt) => refreshTeamAccount(realTeamRefreshDeps(core, publishedAt)))))()let autoSetup: Promise<Pick<TeamAutoSetup, 'offer' | 'decline'>> | null = nullconst disconnect = () => { preparations.clear(); host?.stop(); host = null; held = null; book?.stop(); book = null; bookMachine = null; swarmCards?.want(false); swarmCards = null; cardsMachine = null; tokens.stop(); engines.stop() }const port = {@@ -466,3 +471,33 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =}return { requests, port }}++/** The owner's daemon's own: its account's machine list, and the link to its Mac's team account (team/refresh.ts). */+function realTeamRefreshDeps(core: CoreApi, publishedAt: number | null): TeamRefreshDeps {+ const file = teamRefreshFile(core.dataDir)+ return {+ config: () => readTeamConfig(),+ status: readTeamStatus,+ publishedAt: () => publishedAt,+ machines: async () => {+ const reply = await core.account.backend('GET', '/api/machines')+ const body = object(reply.body), data = object(body.data)+ const rows = Array.isArray(data.machines) ? data.machines : Array.isArray(body.machines) ? body.machines : []+ return rows.map(object).filter(m => typeof m.machineId === 'string')+ .map(m => ({ machineId: m.machineId as string, sessionKind: typeof m.sessionKind === 'string' ? m.sessionKind : null,+ hostMachineId: typeof m.hostMachineId === 'string' ? m.hostMachineId : null }))+ },+ machineId: () => core.daemon.machineId(),+ run: async (machineId, argv, cwd) => {+ const link = await openDaemon({ dataDir: core.dataDir, port: core.daemon.port, machineId: core.daemon.machineId() }, machineId)+ try {+ const answer = object(await link.request('shell_open', { argv, cwd, creationId: refreshCreationId() }, 30_000))+ return answer.state === 'created' ? { ok: true } : { ok: false, error: String(answer.error ?? answer.state ?? 'no answer') }+ } finally { link.close() }+ },+ lastTry: () => readLastTry(file),+ remember: (at) => writeLastTry(file, at),+ now: () => Date.now(),+ log: (line) => console.log(`[team] ${line}`),+ }+}diff --git a/cli/src/team/refresh.spec.ts b/cli/src/team/refresh.spec.tsnew file mode 100644index 000000000..058e0a6d5--- /dev/null+++ b/cli/src/team/refresh.spec.ts@@ -0,0 +1,90 @@+import { mkdtempSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { afterEach, describe, expect, it, vi } from 'vitest'+import { validCreationId } from '../lib/agentCreationReceipt.js'+import type { TeamConfig } from './config.js'+import type { TeamStatus } from './privacy.js'+import {+ readLastTry, refreshCreationId, refreshTeamAccount, TEAM_REFRESH_RETRY_MS, teamBuildStale, writeLastTry, type TeamRefreshDeps,+} from './refresh.js'++const config = { node: '/Users/harnessteam/.harness/runtime/node/bin/node', cli: '/Users/harnessteam/.harness/cli/cli.js',+ home: '/Users/harnessteam', statusFile: '/status.json' } as TeamConfig+const signedOut = (checkedAt: number, relayed = false): TeamStatus => ({ version: 1,+ engines: { checkedAt, claude: { installed: true, signedIn: false, ...(relayed ? { relayed } : {}) }, codex: { installed: true, signedIn: false } } }) as TeamStatus+const cleanup: string[] = []+afterEach(() => { for (const dir of cleanup.splice(0)) rmSync(dir, { recursive: true, force: true }) })++function deps(over: Partial<TeamRefreshDeps> = {}) {+ let last: number | null = null+ const d: TeamRefreshDeps = {+ config: () => config, status: () => signedOut(2_000), publishedAt: () => 1_000,+ machines: async () => [{ machineId: 'mac', sessionKind: 'computer' }, { machineId: 'team', sessionKind: 'team', hostMachineId: 'mac' },+ { machineId: 'other-team', sessionKind: 'team', hostMachineId: 'other' }],+ machineId: () => 'mac', run: vi.fn(async () => ({ ok: true })), lastTry: () => last, remember: vi.fn((at: number) => { last = at }),+ now: () => 5_000, log: vi.fn(), ...over,+ }+ return d+}++describe('a Harness Team account on a build too old for its owner\'s subscriptions', () => {+ it('is read from its own report, checked after the relay was published', () => {+ expect(teamBuildStale(signedOut(2_000), 1_000)).toBe(true)+ // Checked before the relay was there, or before any publish: it could not have seen it yet.+ expect(teamBuildStale(signedOut(500), 1_000)).toBe(false)+ expect(teamBuildStale(signedOut(2_000), null)).toBe(false)+ // A build that knows the relay says so; one engine signed in itself is ready.+ expect(teamBuildStale(signedOut(2_000, true), 1_000)).toBe(false)+ const one = signedOut(2_000); one.engines!.codex.signedIn = true+ expect(teamBuildStale(one, 1_000)).toBe(false)+ const none = signedOut(2_000); none.engines!.claude.installed = false; none.engines!.codex.installed = false+ expect(teamBuildStale(none, 1_000)).toBe(false)+ expect(teamBuildStale(null, 1_000)).toBe(false)+ })++ it('is updated by its owner\'s daemon, as itself, over the link to its own machine; once a day', async () => {+ const d = deps()+ await refreshTeamAccount(d)+ expect(d.run).toHaveBeenCalledWith('team', [config.node, config.cli, 'update', '--force'], '/Users/harnessteam')+ expect(d.remember).toHaveBeenCalledWith(5_000)+ expect(d.log).toHaveBeenCalledWith(expect.stringContaining('updating it'))+ await refreshTeamAccount(d)+ expect(d.run).toHaveBeenCalledOnce()+ await refreshTeamAccount({ ...d, now: () => 5_000 + TEAM_REFRESH_RETRY_MS })+ expect(d.run).toHaveBeenCalledTimes(2)+ })++ it('asks nothing when there is no team account, it is current, or its machine is not this Mac\'s', async () => {+ for (const over of [{ config: () => null }, { status: () => signedOut(2_000, true) }, { machineId: () => 'elsewhere' }] as Array<Partial<TeamRefreshDeps>>) {+ const d = deps(over)+ await refreshTeamAccount(d)+ expect(d.run).not.toHaveBeenCalled()+ }+ })++ it('says why it could not, and never throws', async () => {+ const refused = deps({ run: vi.fn(async () => ({ ok: false, error: 'NO_PEER_LINK' })) })+ await refreshTeamAccount(refused)+ expect(refused.log).toHaveBeenCalledWith(expect.stringContaining('(NO_PEER_LINK); trying again tomorrow'))+ const silent = deps({ run: vi.fn(async () => ({ ok: false })) })+ await refreshTeamAccount(silent)+ expect(silent.log).toHaveBeenCalledWith(expect.stringContaining('(no answer)'))+ const down = deps({ machines: async () => { throw new Error('offline') } })+ await refreshTeamAccount(down)+ expect(down.log).toHaveBeenCalledWith('team: could not update the Harness Team account: offline')+ const odd = deps({ machines: async () => { throw 'odd' } })+ await refreshTeamAccount(odd)+ expect(odd.log).toHaveBeenCalledWith('team: could not update the Harness Team account: odd')+ })++ it('remembers its last try in the daemon\'s own folder, and makes ids the shell takes', () => {+ const dir = mkdtempSync(join(tmpdir(), 'team-refresh-'))+ cleanup.push(dir)+ const file = join(dir, 'sub', 'team-refresh.json')+ expect(readLastTry(file)).toBeNull()+ writeLastTry(file, 42)+ expect(readLastTry(file)).toBe(42)+ expect(validCreationId(refreshCreationId())).toBe(true)+ })+})diff --git a/cli/src/team/refresh.ts b/cli/src/team/refresh.tsnew file mode 100644index 000000000..2226aab83--- /dev/null+++ b/cli/src/team/refresh.ts@@ -0,0 +1,90 @@+/**+ * A Harness Team account left on a build too old for its owner's subscriptions is brought up to date by its owner's+ * daemon, with nobody at the Mac.+ *+ * Setup copies the owner's CLI into the team account. An owner on a local build (a developer's) gave it that build, and+ * a local build never updated itself, so the account stayed on it (2026-10-27): no owner subscription relay, its engines+ * read signed out, and the Lead routed nothing there. Its updater now follows releases (lib/selfUpdate.ts+ * `followReleases`), but a team account already on such a build has the old updater, so the owner's daemon starts the+ * update there once: `harness update --force` as the team account, through the shell request its own apps use+ * (services/shell.ts `shell_open`) over the link to that machine. The team account's own Node and CLI, from the+ * root-owned config, run it. Nothing is written into the team account's home from outside.+ *+ * Asked only when the team account says so itself: its status file reports engines it has neither signed in nor reached+ * the owner's relay for, checked after this daemon published the relay, which a build that knows the relay never does.+ * At most once a day, remembered in this daemon's own folder.+ */+import { randomUUID } from 'node:crypto'+import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'+import { dirname, join } from 'node:path'+import type { TeamConfig } from './config.js'+import type { TeamStatus } from './privacy.js'+import { TEAM_ENGINES } from './engines.js'++/** How long after one try the owner's daemon may try again. */+export const TEAM_REFRESH_RETRY_MS = 24 * 60 * 60_000++export interface TeamRefreshDeps {+ config(): TeamConfig | null+ status(path: string): TeamStatus | null+ /** When this daemon last published the owner's relay (team/relay.ts), or null before it has. */+ publishedAt(): number | null+ /** The account's machines, from `GET /api/machines`: the team account of this Mac is among them. */+ machines(): Promise<Array<{ machineId: string; sessionKind?: string | null; hostMachineId?: string | null }>>+ /** This Mac's own machine id. */+ machineId(): string+ /** Runs [argv] in [cwd] as a terminal on [machineId], over the link (`shell_open`). */+ run(machineId: string, argv: string[], cwd: string): Promise<{ ok: boolean; error?: string }>+ lastTry(): number | null+ remember(at: number): void+ now(): number+ log(line: string): void+}++/** Whether the team account's own report says its build cannot use the owner's relay. */+export function teamBuildStale(status: TeamStatus | null, publishedAt: number | null): boolean {+ const engines = status?.engines+ if (!engines || publishedAt === null || engines.checkedAt < publishedAt) return false+ const installed = TEAM_ENGINES.filter(({ engine }) => engines[engine].installed)+ return installed.length > 0 && installed.every(({ engine }) => engines[engine].signedIn !== true && !engines[engine].relayed)+}++/** One look: updates the team account when its build is too old, at most once a day. Never throws. */+export async function refreshTeamAccount(deps: TeamRefreshDeps): Promise<void> {+ try {+ const config = deps.config()+ if (!config || !teamBuildStale(deps.status(config.statusFile), deps.publishedAt())) return+ const last = deps.lastTry()+ if (last !== null && deps.now() - last < TEAM_REFRESH_RETRY_MS && deps.now() >= last) return+ const here = deps.machineId()+ const team = (await deps.machines()).find((m) => m.sessionKind === 'team' && m.hostMachineId === here)+ if (!team) return+ deps.remember(deps.now())+ const answer = await deps.run(team.machineId, [config.node, config.cli, 'update', '--force'], config.home)+ deps.log(answer.ok+ ? 'team: the Harness Team account was on a build without this Mac\'s subscriptions; updating it'+ : `team: could not update the Harness Team account (${answer.error ?? 'no answer'}); trying again tomorrow`)+ } catch (error) {+ deps.log(`team: could not update the Harness Team account: ${error instanceof Error ? error.message : String(error)}`)+ }+}++/** Where the owner's daemon remembers its last try, in its own data folder. */+export const teamRefreshFile = (dataDir: string) => join(dataDir, 'team-refresh.json')++export function readLastTry(file: string): number | null {+ try {+ const at = (JSON.parse(readFileSync(file, 'utf8')) as { at?: unknown }).at+ return typeof at === 'number' && Number.isFinite(at) ? at : null+ } catch { return null }+}++export function writeLastTry(file: string, at: number): void {+ mkdirSync(dirname(file), { recursive: true })+ const next = `${file}.${process.pid}.next`+ writeFileSync(next, `${JSON.stringify({ at })}\n`, { mode: 0o600 })+ renameSync(next, file)+}++/** A creation id `shell_open` takes (lib/agentCreationReceipt.ts `validCreationId`). */+export const refreshCreationId = () => `team-update-${randomUUID().replace(/-/g, '')}`diff --git a/cli/src/team/relay.spec.ts b/cli/src/team/relay.spec.tsindex 1dca87584..e61fb9a8a 100644--- a/cli/src/team/relay.spec.ts+++ b/cli/src/team/relay.spec.ts@@ -103,6 +103,19 @@ describe('the owner\'s daemon, for the Harness Team account', () => {.rejects.toThrow()})+ it('after each look, says when it last published, for a team account on an older build to be updated', async () => {+ const afterPass = vi.fn(async () => {})+ let present: TeamConfig | null = config+ const f = publisher({ afterPass, now: () => 7, config: () => present })+ await f.p.tick()+ expect(afterPass).toHaveBeenLastCalledWith(7)+ await f.p.tick()+ expect(afterPass).toHaveBeenCalledTimes(2)+ present = null+ await f.p.tick()+ expect(afterPass).toHaveBeenCalledTimes(2)+ })+it('names one folder per owner under /Users/Shared', () => {expect(teamRelayDir('owner')).toBe('/Users/Shared/.harness-team-relay-owner')expect(teamRelayFile('owner')).toBe('/Users/Shared/.harness-team-relay-owner/relay.json')diff --git a/cli/src/team/relay.ts b/cli/src/team/relay.tsindex ffb8fb478..96b7791f9 100644--- a/cli/src/team/relay.ts+++ b/cli/src/team/relay.ts@@ -55,6 +55,10 @@ export interface TeamRelayPublisherDeps {withdraw(owner: string): voidlog(line: string): voidintervalMs?: number+ now?: () => number+ /** After each look, with when the relay was last published (null before): a team account on a build too old for it+ * is updated (./refresh.ts). */+ afterPass?: (publishedAt: number | null) => Promise<void>}/** How often the owner's daemon looks again: a team account set up later gets its relay within this long. */@@ -66,6 +70,7 @@ export class TeamRelayPublisher {private grant: TeamRelayGrant | null = nullprivate owner: string | null = nullprivate running: Promise<void> | null = null+ private publishedAt: number | null = nullconstructor(private readonly deps: TeamRelayPublisherDeps) {}start(): void {@@ -78,7 +83,7 @@ export class TeamRelayPublisher {tick(): Promise<void> {return this.running ??= this.pass().catch((error: unknown) => {this.deps.log(`team relay: ${error instanceof Error ? error.message : String(error)}`)- }).finally(() => { this.running = null })+ }).then(() => this.owner ? this.deps.afterPass?.(this.publishedAt) : undefined).finally(() => { this.running = null })}private async pass(): Promise<void> {@@ -92,6 +97,7 @@ export class TeamRelayPublisher {const relay = await this.relay.catch((error: unknown) => { this.relay = null; throw error })this.grant ??= { url: relay.url, token: relay.mintToken(TEAM_RELAY_GUEST) }await this.deps.publish(config, this.grant)+ this.publishedAt = (this.deps.now ?? Date.now)()this.owner = config.ownerthis.deps.log('team relay: the Harness Team account uses this Mac\'s subscriptions')}@@ -100,6 +106,7 @@ export class TeamRelayPublisher {if (this.owner) this.deps.withdraw(this.owner)this.owner = nullthis.grant = null+ this.publishedAt = nullconst relay = await this.relay?.catch(() => null)this.relay = nullawait relay?.close()@@ -145,8 +152,9 @@ export const teamRelayPublished = (config: TeamConfig, exists: (path: string) =>}) => exists(teamRelayFile(config.owner))export function realTeamRelayPublisher(startRelay: () => Promise<SubscriptionRelay>, config: () => TeamConfig | null,- team: () => boolean, log: (line: string) => void): TeamRelayPublisher {+ team: () => boolean, log: (line: string) => void, afterPass?: (publishedAt: number | null) => Promise<void>): TeamRelayPublisher {return new TeamRelayPublisher({+ ...(afterPass ? { afterPass } : {}),// Tests inject a publisher: a test never reads this Mac's own team account, starts a relay on the owner's sign-ins,// or writes to /Users/Shared (a service spec did, 2026-10-27). Production never has VITEST set.config: () => process.env.VITEST ? null : config(),diff --git a/docs/plans/2026-10-24-swarm-team-account.md b/docs/plans/2026-10-24-swarm-team-account.mdindex 076bcd228..b7cb29a6e 100644--- a/docs/plans/2026-10-24-swarm-team-account.md+++ b/docs/plans/2026-10-24-swarm-team-account.md@@ -122,6 +122,17 @@ ask again. The team account's engines also needed signing in by hand, and the Leuser alone read it. The team daemon uses it for an engine it has not signed in itself, on every launch and relaunch(Codex is named the relay's provider in place of its own login's), and reports that engine ready to the Swarm.+- **Nothing to run by hand (2026-10-27).** Two things kept a Mac's team account out of its Swarms, each fixed in code:+ - *A device list frozen by the backend's race (#1789)* trusted no new device, the team account's machine included,+ so its owner's daemon could not reach it ("not linked"). A list frozen as `invalid` now heals itself once the+ backend serves the entries it claimed, when they continue the chain this machine verified+ (lib/e2ee/deviceLogSyncer.ts); a rollback or fork still waits for a person.+ - *A team account copied from a local build* never updated itself. Its updater now follows releases+ (lib/selfUpdate.ts `followReleases`), and one already on such a build is updated by its owner's daemon: when its+ status file shows engines neither signed in nor using the relay, checked after the relay was published, the owner's+ daemon runs `harness update --force` as the team account over the link (`shell_open`), at most once a day+ (team/refresh.ts).+### Design- **Growth:** one file per Mac, rewritten in place; removed when the team account is gone or the owner's daemon stops.