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: nothing changes for anyone who never had a team machine (#1702)
Dee942ce63522e8
diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex ecc4a4192..66e28d284 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -157,12 +157,6 @@ Machine:harness service uninstall undo that: the daemon goes back to \`harness start\`harness service status what launchd, systemd or Task Scheduler has registered, and whether it runs (--json)harness logs export zip the last 7 days of logs (app, CLI, dial, daemon) to the Desktop- harness team setup on a Mac: a separate account, Harness Team, whose own daemon runs teammates' Swarm- agents so they cannot read your files (one administrator password; again repairs it)- harness team status whether that account exists and runs, its sign-in and privacy check, and what it made- harness team remove delete that account, its home folder and its daemon (in Terminal: sudo, then macOS- asks to let Terminal administer your computer)- harness team on|off a computer used only for agents: sign it in for team work only, or back as your ownharness tui all of Harness in this terminal: swarms, panes, every machine (⌥O ⌥P ⌥N)harness new [agent] [--machine <name>] [folder|name] [-- task]make a harness from a shell: \`harness new\` is claude here; see \`harness new -h\`diff --git a/cli/src/lib/e2ee/groupSyncer.spec.ts b/cli/src/lib/e2ee/groupSyncer.spec.tsindex 279fcf339..43dfaca0f 100644--- a/cli/src/lib/e2ee/groupSyncer.spec.ts+++ b/cli/src/lib/e2ee/groupSyncer.spec.ts@@ -44,6 +44,8 @@ interface Node {/** What this machine's copy of the account's machine list says each machine is; `kindOf` for any it does not name. */kinds: Map<string, 'team' | 'computer' | null>kindOf: 'team' | 'computer' | null+ /** No team machine ever on this computer (machineKinds.ts teamFree): the trust group as before team machines. */+ teamFree: boolean/** How often the list was read again. */reads: number}@@ -74,6 +76,7 @@ function fleet(): { add: (name: string, machine?: boolean) => Node; link: (joinedroppedSessions: [],kinds: new Map(),kindOf: 'computer',+ teamFree: false,reads: 0,} as unknown as Nodenode.syncer = new S.GroupSyncer({@@ -87,6 +90,7 @@ function fleet(): { add: (name: string, machine?: boolean) => Node; link: (joinemachineKinds: {kind: (machineId) => node.kinds.has(machineId) ? node.kinds.get(machineId)! : node.kindOf,fresh: async () => { node.reads++ },+ teamFree: () => node.teamFree,},request: async (machineId, frame: Frame) => {const target = nodes.find((n) => n.machineId === machineId)@@ -230,6 +234,23 @@ describe('GroupSyncer', () => {for (const n of f.nodes) n.syncer.stop()})+ it('syncs as before team machines on a computer that never had one, whatever the list says or fails to say', async () => {+ vi.useFakeTimers()+ const f = fleet()+ const [a, b] = [f.add('a'), f.add('b')]+ f.link(a, b)+ // A regular user: no list read yet, a stale one, or a new machine not on it.+ for (const n of [a, b]) { n.kindOf = null; n.teamFree = true }+ const handle = vi.spyOn(b.syncer, 'handle')+ expect(await a.syncer.syncWith(b.machineId!)).toBe(true)+ expect(handle).toHaveBeenCalled()+ const self = { pub: a.pub, kind: 'machine', label: 'a', machineId: a.machineId, at: S.SELF_STAMP }+ expect(b.syncer.handle(a.pub, { self, members: [], removed: [] }).error).toBeUndefined()+ const stray = C.b64e(C.newIdentity().pub)+ expect(b.syncer.handle(stray, { self: { pub: stray, kind: 'machine', label: 's', at: S.SELF_STAMP }, members: [], removed: [] }).error).toBeUndefined()+ for (const n of f.nodes) n.syncer.stop()+ })+it('A links B, A links C ⇒ B and C reach each other both ways, no password', async () => {vi.useFakeTimers()const f = fleet()diff --git a/cli/src/lib/e2ee/groupSyncer.ts b/cli/src/lib/e2ee/groupSyncer.tsindex 186e10158..8709ef8ba 100644--- a/cli/src/lib/e2ee/groupSyncer.ts+++ b/cli/src/lib/e2ee/groupSyncer.ts@@ -75,7 +75,9 @@ export interface GroupSyncerDeps {shared?: (pub: string) => boolean/** What the account's machine list says a machine is (machineKinds.ts): only `computer`, one of the person's own,* takes part in the group. `team` and unknown (null) never do. `fresh` reads the list again when it is old. */- machineKinds: { kind: (machineId: string) => MachineKind | null; fresh?: () => Promise<void> }+ machineKinds: { kind: (machineId: string) => MachineKind | null; fresh?: () => Promise<void>+ /** No team machine ever on this computer (machineKinds.ts): every machine syncs as before team machines. */+ teamFree?: () => boolean }/** Whether the roster here is the account's this machine is signed in to (deviceLogSyncer `current`).* While not, nothing is swapped: a daemon started after a switch of accounts read the new account's* log only after its first rounds, and handed the roster of the account it left to the new one's@@ -338,7 +340,7 @@ export class GroupSyncer {/** Whether the account's machine list says [machineId] is one of the person's own machines. */private ordinary(machineId: string): boolean {- return this.deps.machineKinds.kind(machineId) === 'computer'+ return this.deps.machineKinds.teamFree?.() === true || this.deps.machineKinds.kind(machineId) === 'computer'}/**@@ -348,6 +350,7 @@ export class GroupSyncer {* machine. A peer no record or word of its own makes a machine (a phone, a desktop app) is not a machine at all.*/private machinePeerRefusal(peerPub: string, claimedSelf: unknown): 'TEAM_MACHINE' | 'MACHINE_UNKNOWN' | null {+ if (this.deps.machineKinds.teamFree?.() === true) return nullconst ids = new Set<string>()let machine = falsefor (const p of this.deps.peers.list()) if (p.pub === peerPub) { ids.add(p.machineId); machine = true }diff --git a/cli/src/lib/e2ee/machineKinds.spec.ts b/cli/src/lib/e2ee/machineKinds.spec.tsindex 81922191b..16cf89b08 100644--- a/cli/src/lib/e2ee/machineKinds.spec.ts+++ b/cli/src/lib/e2ee/machineKinds.spec.ts@@ -1,3 +1,6 @@+import { existsSync, mkdtempSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'import { describe, expect, it, vi } from 'vitest'import { MACHINE_KINDS_MAX_AGE_MS, MACHINE_KINDS_REFRESH_MS, MachineKinds, machineKindsOf } from './machineKinds.js'@@ -25,7 +28,7 @@ describe('MachineKinds', () => {it('knows nothing until a list is read, then goes by it until it is too old', async () => {let now = 1_000const read = vi.fn(async (): Promise<unknown> => list('computer'))- const kinds = new MachineKinds({ read, now: () => now })+ const kinds = new MachineKinds({ file: null, read, now: () => now })expect(kinds.kind('m1')).toBeNull()await kinds.fresh()expect(kinds.kind('m1')).toBe('computer')@@ -37,7 +40,7 @@ describe('MachineKinds', () => {it('reads again only once the list is old, one read at a time, and keeps the last list when a read fails', async () => {let now = 1_000const read = vi.fn(async (): Promise<unknown> => list('computer'))- const kinds = new MachineKinds({ read, now: () => now })+ const kinds = new MachineKinds({ file: null, read, now: () => now })await Promise.all([kinds.fresh(), kinds.fresh()])expect(read).toHaveBeenCalledTimes(1)await kinds.fresh()@@ -55,13 +58,13 @@ describe('MachineKinds', () => {expect(kinds.kind('m1')).toBe('team')})- it('takes a list the gateway read for the apps, and forgets everything on a sign-out, a read on its way included', async () => {+ it('takes a list the gateway read for the apps, and forgets the list on a sign-out, a read on its way included', async () => {let release: (body: unknown) => void = () => {}- const kinds = new MachineKinds({ read: () => new Promise((resolve) => { release = resolve }) })- kinds.adopt(list('team'))- expect(kinds.kind('m1')).toBe('team')+ const kinds = new MachineKinds({ file: null, read: () => new Promise((resolve) => { release = resolve }) })+ kinds.adopt(list('computer'))+ expect(kinds.kind('m1')).toBe('computer')kinds.adopt({ nothing: true })- expect(kinds.kind('m1')).toBe('team')+ expect(kinds.kind('m1')).toBe('computer')kinds.clear()expect(kinds.kind('m1')).toBeNull()const reading = kinds.fresh()@@ -69,5 +72,32 @@ describe('MachineKinds', () => {release(list('computer'))await readingexpect(kinds.kind('m1')).toBeNull()+ // A team machine is remembered past a sign-out: it is still one.+ kinds.adopt(list('team'))+ kinds.clear()+ expect(kinds.kind('m1')).toBe('team')+ })++ it('is team-free, as every regular user is, until a list shows a team machine; remembered on disk until a list shows it as a computer', async () => {+ const file = join(mkdtempSync(join(tmpdir(), 'kinds-')), 'e2e', 'team-machines.json')+ const kinds = new MachineKinds({ file, read: async () => null })+ expect(kinds.teamFree()).toBe(true)+ kinds.adopt({ machines: [{ machineId: 'own', sessionKind: 'computer' }, { machineId: 'old' }] })+ expect(kinds.teamFree()).toBe(true)+ expect(existsSync(file)).toBe(false)+ kinds.adopt({ machines: [{ machineId: 'own', sessionKind: 'computer' }, { machineId: 'team-1', sessionKind: 'team' }] })+ expect(kinds.teamFree()).toBe(false)+ // A restart, signed out or offline: the team machine is still known.+ const restarted = new MachineKinds({ file, read: async () => null })+ expect(restarted.teamFree()).toBe(false)+ expect(restarted.kind('team-1')).toBe('team')+ expect(restarted.kind('own')).toBeNull()+ // `harness team off`: the list shows it as the person's own again.+ restarted.adopt({ machines: [{ machineId: 'team-1', sessionKind: 'computer' }] })+ expect(restarted.teamFree()).toBe(true)+ expect(new MachineKinds({ file, read: async () => null }).teamFree()).toBe(true)+ // An unreadable file is no team machine.+ writeFileSync(file, 'not json')+ expect(new MachineKinds({ file, read: async () => null }).teamFree()).toBe(true)})})diff --git a/cli/src/lib/e2ee/machineKinds.ts b/cli/src/lib/e2ee/machineKinds.tsindex 81981c68e..856ef4a17 100644--- a/cli/src/lib/e2ee/machineKinds.ts+++ b/cli/src/lib/e2ee/machineKinds.ts@@ -8,7 +8,16 @@* trusted than a machine shared from another account: its roster must never change the keys the person's own machines* trust, and theirs is not sent to it (groupSyncer.ts). So a machine whose kind cannot be read — no list from the* backend yet, a list too old to go by, a machine the list does not hold — is treated as one that may not take part.+ *+ * Only on a computer where an account has had a team machine ([MachineKinds.teamFree]). Team machines exist only for+ * Swarm work, a hidden feature; everyone else's machines sync as they did before team machines, whatever the list says+ * or fails to say. The team machines a list has shown are remembered on disk, so a restart or a list that cannot be read+ * does not forget them.*/+import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'+import { dirname, join } from 'node:path'+import { env } from '../../config/env.js'+export type MachineKind = 'team' | 'computer'/** A list is read again before a round once it is this old. */@@ -38,6 +47,22 @@ export interface MachineKindsDeps {/** The account's machine list as the backend answered it; null when it could not be read (offline, signed out). */read: () => Promise<unknown>now?: () => number+ /** Where the team machines a list has shown are remembered (beside the trust stores, lib/e2ee/store.ts); null keeps+ * them in memory only. */+ file?: string | null+}++/** The team machines a list has shown on this computer, for any account. */+export const TEAM_MACHINES_FILE = join(env.ADAPTER_DATA_DIR, 'e2e', 'team-machines.json')++function readRemembered(file: string | null): Set<string> {+ if (!file) return new Set()+ try {+ const ids = (JSON.parse(readFileSync(file, 'utf8')) as { teamMachineIds?: unknown }).teamMachineIds+ return new Set(Array.isArray(ids) ? ids.filter((id): id is string => typeof id === 'string' && id.length > 0) : [])+ } catch {+ return new Set()+ }}/** The last machine list read, and reading it again when it is old. */@@ -47,9 +72,12 @@ export class MachineKinds {private reading: Promise<void> | null = nullprivate generation = 0private readonly now: () => number+ private readonly file: string | null+ private remembered: Set<string> | null = nullconstructor(private readonly deps: MachineKindsDeps) {this.now = deps.now ?? Date.now+ this.file = deps.file === undefined ? TEAM_MACHINES_FILE : deps.file}/** A list the backend just answered (the gateway's own machine list, read for the apps). */@@ -58,6 +86,12 @@ export class MachineKinds {if (!kinds) returnthis.kinds = kindsthis.readAt = this.now()+ this.remember(kinds)+ }++ /** Whether no account on this computer has had a team machine: then every machine syncs as before team machines. */+ teamFree(): boolean {+ return this.known().size === 0}/** Signed out, or another account: nothing is known any more, and a read on its way is not taken. */@@ -69,10 +103,32 @@ export class MachineKinds {/** What the list says [machineId] is; null when it cannot say. */kind(machineId: string): MachineKind | null {+ if (this.known().has(machineId)) return 'team'if (!this.kinds || this.now() - this.readAt > MACHINE_KINDS_MAX_AGE_MS) return nullreturn this.kinds.get(machineId) ?? null}+ private known(): Set<string> {+ return this.remembered ??= readRemembered(this.file)+ }++ /** A list's team machines are remembered, and one it now shows as a computer of the person's own (`harness team off`,+ * or a normal sign-in taking it over) is not. Kept in memory even when it cannot be written, until the daemon stops. */+ private remember(kinds: Map<string, MachineKind>): void {+ const known = this.known()+ let changed = false+ for (const [id, kind] of kinds) {+ if (kind === 'team' && !known.has(id)) { known.add(id); changed = true }+ if (kind === 'computer' && known.delete(id)) changed = true+ }+ if (!changed || !this.file) return+ try {+ mkdirSync(dirname(this.file), { recursive: true, mode: 0o700 })+ writeFileSync(`${this.file}.next`, JSON.stringify({ teamMachineIds: [...known] }), { mode: 0o600 })+ renameSync(`${this.file}.next`, this.file)+ } catch { /* memory keeps them */ }+ }+/** Read the list again unless it is recent; one read at a time. Never throws. */fresh(): Promise<void> {if (this.kinds && this.now() - this.readAt < MACHINE_KINDS_REFRESH_MS) return Promise.resolve()diff --git a/cli/src/superTabs/service.spec.ts b/cli/src/superTabs/service.spec.tsindex fd41730fd..395b93660 100644--- a/cli/src/superTabs/service.spec.ts+++ b/cli/src/superTabs/service.spec.ts@@ -1,4 +1,7 @@import { createHash } from 'node:crypto'+import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { dirname, join } from 'node:path'import { describe, expect, it, vi } from 'vitest'import { fakeCore } from '../testing/fakeCore.js'import type { CoreApi } from '../core/api.js'@@ -6,7 +9,7 @@ import { sharedSwarm, superTabService } from './service.js'import { object } from './wire.js'const list = (value: unknown) => Array.isArray(value) ? value.map(object) : []-import { SuperTabHostError, type SuperTabHost, type SuperTabHostOptions } from './host.js'+import { hostJournalFile, SuperTabHostError, type SuperTabHost, type SuperTabHostOptions } from './host.js'const owner = { local: true, owner: true }, visitor = { local: false, owner: false }function setup(options: { prepareContribution?: typeof import('./contribution.js').prepareContribution } = {}) {@@ -706,11 +709,25 @@ describe('the Harness Team account, offered by Desktop on this Mac', () => {for (const reason of [undefined, 'background', 7]) {expect(await service.requests.super_tabs({ action: 'teamSetup', reason }, owner)).toEqual({ error: 'INVALID_REQUEST' })}- await service.requests.super_tabs({ action: 'teamSetup', reason: 'startup' }, owner)+ await service.requests.super_tabs({ action: 'teamSetup', reason: 'contribute' }, owner)expect(make).toHaveBeenCalledTimes(1)expect(offer).toHaveBeenCalledTimes(2)})+ it('at app start, answers at once on a Mac that hosts no Swarm work, as no regular user\'s does', async () => {+ const offer = vi.fn(async (_reason: string, _shared: () => Promise<boolean>) => ({ state: 'not-shared' as const }))+ const make = vi.fn(async () => ({ offer }))+ const dataDir = mkdtempSync(join(tmpdir(), 'team-startup-'))+ const service = superTabService(fakeCore({ dataDir }), { teamSetup: make })+ expect(await service.requests.super_tabs({ action: 'teamSetup', reason: 'startup' }, owner)).toEqual({ ok: true, state: 'not-shared' })+ expect(make).not.toHaveBeenCalled()+ // Once this Mac hosts Swarm work, the offer decides.+ mkdirSync(dirname(hostJournalFile(dataDir, 'machine-1')), { recursive: true })+ writeFileSync(hostJournalFile(dataDir, 'machine-1'), '{}')+ await service.requests.super_tabs({ action: 'teamSetup', reason: 'startup' }, owner)+ expect(offer).toHaveBeenCalledWith('startup', expect.any(Function))+ })+it('tries again to make its setup when making it failed', async () => {const make = vi.fn().mockRejectedValueOnce(new Error('import failed')).mockResolvedValueOnce({ offer: async () => ({ state: 'exists' }) })const service = superTabService(fakeCore(), { teamSetup: make })diff --git a/cli/src/superTabs/service.ts b/cli/src/superTabs/service.tsindex d8e178c0e..02e1e875f 100644--- a/cli/src/superTabs/service.ts+++ b/cli/src/superTabs/service.ts@@ -231,6 +231,11 @@ export function superTabService(core: CoreApi, options: SuperTabServiceOptions =if (payload.action === 'teamSetup') {if (!asker.local) return { error: 'OWNER_REQUIRED' }if (!AUTO_SETUP_REASONS.includes(payload.reason as AutoSetupReason)) return { error: 'INVALID_REQUEST' }+ // Desktop asks at every launch. A Mac that hosts no Swarm work, as no regular user's does, answers at once:+ // nothing read, run or asked of the backend.+ if (payload.reason === 'startup' && !(identifier(core.daemon.machineId()) && existsSync(hostJournalFile(core.dataDir, core.daemon.machineId())))) {+ return { ok: true, state: 'not-shared' }+ }autoSetup ??= (options.teamSetup ?? (() => realTeamAutoSetup(core.dataDir, line => console.log(`[team] ${line}`))))().catch(error => { autoSetup = null; throw error })return { ok: true, ...await (await autoSetup).offer(payload.reason as AutoSetupReason, () => sharedSwarm(core)) }