Skip to content

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.

feat(cli): read a Swarm, the team log and the team engines' sign-in from a headless shell (#2905)

lingrd2170236a27da
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 915ae5e7d..e34101940 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -185,6 +185,8 @@ Machine:
harness 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\`
+ harness swarm [list|status|machines|agents|starts]
+ the Swarm as you read it: people, machines, agents, starts
harness machines list the machines on this account (this computer's is marked)
harness search <words> find the conversation on this computer that said them: every turn of
every harness, live or stopped (--limit=N, --json)
@@ -3108,6 +3110,27 @@ switch (cmd) {
serviceCommand(rest, serviceCommandDeps({ relaunch: () => launch(false), tildify }))
.then((code) => { process.exitCode = code }).catch(onError)
break
+ case 'swarm':
+ import('./swarm/command.js')
+ .then(({ swarmCommand }) => swarmCommand(rest, {
+ out: (line) => console.log(line),
+ err: (line) => console.error(line),
+ auth: controlPlaneAuth,
+ get: (path, headers) => requestJson('GET', path, undefined, headers),
+ }, flags.includes('--json')))
+ .then((code) => { process.exitCode = code }).catch(onError)
+ break
+ case 'team':
+ // `team ps`: the harnesses of the account's Harness Team machine, which plain `ps` hides (they belong to another
+ // account on this computer): the same read, with --machine already named (headless run, 2026-11-03).
+ if (rest[0] === 'ps') {
+ usableMachines().then(async (machines) => {
+ const team = machines.find((machine) => machine.label.endsWith('· Team'))
+ if (!team) { console.error('No Harness Team account on this account yet: harness team setup makes one.'); return 1 }
+ return psCommand(['--machine', team.label, '--all', ...rest.slice(1)], { machines: async () => machines })
+ }).then((code) => { process.exitCode = code }).catch(onError)
+ break
+ }
case 'team':
// Loaded only here (team/deps.ts). The daemon is stopped before a sign-in changes under it and started again on the
// new one; `launch` prints its status block and exits, so it is always the last step.
diff --git a/cli/src/swarm/command.spec.ts b/cli/src/swarm/command.spec.ts
new file mode 100644
index 000000000..024c6fbbf
--- /dev/null
+++ b/cli/src/swarm/command.spec.ts
@@ -0,0 +1,103 @@
+import { describe, expect, it, vi } from 'vitest'
+import { swarmCommand, SWARM_USAGE } from './command.js'
+
+const session = { machineId: 'm1' } as never
+const headers = { authorization: 'Bearer x' }
+const parts = (over: Record<string, unknown> = {}) => ({
+ tabId: 't1', format: 2, serverTime: Date.now(), lastChangedAt: Date.now() - 3000,
+ head: { data: { id: 't1', name: 'autonomous-harness', ownerId: 'u1', paused: false } },
+ members: [{ data: { id: 'u1', email: '[email protected]', role: 'owner' } }],
+ machines: [{ data: { machineId: 'm1', name: 'gridtest', contributorId: 'u1', engines: ['claude'], sessionKind: 'team',
+ observation: { receivedAt: Date.now() - 2000 } } }],
+ agents: [{ data: { id: 'a1', name: 'Lead', machineId: 'm1', configuration: { engine: 'claude' }, leadOf: 'p1' } }],
+ groups: [{ data: { id: 'lead', title: 'autonomous-harness', leadId: 'a1' } }],
+ starts: [
+ { data: { id: 's1', harnessId: 'h1', request: { name: 'builder one', conversationId: 'lead', machineId: 'm1' }, requestedAt: Date.now() - 1000 } },
+ { data: { id: 's2', error: 'Its machine could not prepare or launch it.', request: { name: 'builder two', conversationId: 'lead', machineId: 'm1' }, requestedAt: Date.now() - 4000 } },
+ ],
+ ...over,
+})
+
+function setup(routes: Record<string, unknown>, over: Record<string, unknown> = {}) {
+ const out: string[] = [], errors: string[] = []
+ const get = vi.fn(async (path: string) => routes[path] ?? {})
+ const deps = { out: (line: string) => out.push(line), err: (line: string) => errors.push(line),
+ auth: async () => ({ session, headers }), get, ...over }
+ return { deps, out, errors, get }
+}
+
+const routes = {
+ '/api/super-tabs/list': { tabs: [{ id: 't1', name: 'autonomous-harness' }] },
+ '/api/super-tabs/t1/parts': parts(),
+}
+
+describe('harness swarm', () => {
+ it('lists Swarms with their people, machines and work', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['list'], f.deps)).toBe(0)
+ const text = f.out.join('\n')
+ expect(text).toContain('SWARM')
+ expect(text).toContain('autonomous-harness')
+ expect(text).toContain('1 agent, 1 failed')
+ })
+
+ it('shows one Swarm: people, machines, work, lead, updated', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['status'], f.deps)).toBe(0)
+ const text = f.out.join('\n')
+ expect(text).toContain('autonomous-harness')
+ expect(text).toContain('people 1')
+ expect(text).toContain('machines 1')
+ expect(text).toContain('work 1 running, 0 pending, 1 failed')
+ expect(text).toContain('lead Lead on gridtest (team account)')
+ })
+
+ it('lists machines with owner, engines, agents and state, and never draws icons', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['machines'], f.deps)).toBe(0)
+ const text = f.out.join('\n')
+ expect(text).toContain('MACHINE')
+ expect(text).toContain('gridtest (team account)')
+ expect(text).toContain('[email protected]')
+ expect(text).toContain('live')
+ expect(text).not.toContain('·')
+ })
+
+ it('lists agents with their machine and engine', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['agents'], f.deps)).toBe(0)
+ expect(f.out.join('\n')).toContain('Lead')
+ expect(f.out.join('\n')).toContain('claude')
+ })
+
+ it('lists starts and says why one failed', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['starts'], f.deps)).toBe(0)
+ const text = f.out.join('\n')
+ expect(text).toContain('builder one')
+ expect(text).toContain('running')
+ expect(text).toContain('failed: Its machine could not prepare or launch it.')
+ expect(text).toContain('Why it failed')
+ })
+
+ it('names one Swarm with --tab, and prints help without a verb', async () => {
+ const f = setup(routes)
+ expect(await swarmCommand(['status', '--tab', 't1'], f.deps)).toBe(0)
+ expect(f.get).toHaveBeenCalledWith('/api/super-tabs/t1/parts', headers)
+ expect(await swarmCommand([], f.deps)).toBe(0)
+ expect(f.out.join('\n')).toContain('Usage: harness swarm')
+ expect(SWARM_USAGE).toContain('starts')
+ })
+
+ it('says there is no Swarm instead of failing', async () => {
+ const f = setup({ '/api/super-tabs/list': { tabs: [] } })
+ expect(await swarmCommand(['status'], f.deps)).toBe(0)
+ expect(f.out.join('\n')).toContain('No Swarm on this account yet.')
+ })
+
+ it('reports a refused read as one plain line', async () => {
+ const f = setup({}, { get: async () => { throw new Error('You are not a member of this Swarm.') } })
+ expect(await swarmCommand(['status', '--tab', 't1'], f.deps)).toBe(1)
+ expect(f.errors.join('\n')).toContain('error: You are not a member of this Swarm.')
+ })
+})
diff --git a/cli/src/swarm/command.ts b/cli/src/swarm/command.ts
new file mode 100644
index 000000000..5d6795328
--- /dev/null
+++ b/cli/src/swarm/command.ts
@@ -0,0 +1,230 @@
+/**
+ * `harness swarm …`: a Swarm as the person at this computer reads it.
+ *
+ * The Desktop and the web read a Swarm through the same backend parts this does
+ * (`GET /api/super-tabs/:tabId/parts`). Until now the CLI could only read it as an agent inside a participating
+ * harness (`harness super-tab`), so a person at a headless server could not answer "did my machine join, is there
+ * work, why did my start fail" without a browser (headless run, 2026-11-03).
+ *
+ * Output is plain text in aligned columns: no icons, no digraphs in prose.
+ */
+import type { AuthSession } from '../lib/authSession.js'
+import { controlPlaneAuth, requestJson } from '../lib/controlPlane.js'
+
+type Json = Record<string, unknown>
+const object = (value: unknown): Json => value && typeof value === 'object' && !Array.isArray(value) ? value as Json : {}
+const list = (value: unknown): Json[] => Array.isArray(value) ? value.map(object) : []
+const text = (value: unknown): string => typeof value === 'string' ? value : ''
+
+export interface SwarmDeps {
+ out(line: string): void
+ err(line: string): void
+ auth(): Promise<{ session: AuthSession; headers: Record<string, string> }>
+ get(path: string, headers: Record<string, string>): Promise<unknown>
+}
+
+export const SWARM_USAGE = [
+ 'Usage: harness swarm <list | status | machines | agents | starts> [--tab <id>]',
+ '',
+ ' list the Swarms this account is in',
+ ' status one Swarm: people, machines, this computer, work',
+ ' machines the machines it can run agents on, and their state',
+ ' agents the agents in it, their machine and engine',
+ ' starts agent starts: running, pending, and why one failed',
+ '',
+ 'It reads as you do; no harness of yours has to be running. --tab names one; the first is used otherwise.',
+].join('\n')
+
+/** How old a machine reading may be before it is late, then offline (the Desktop's numbers). */
+const LIVE_MS = 20_000
+const LATE_MS = 35_000
+
+function ago(ms: number, now = Date.now()): string {
+ const seconds = Math.max(0, Math.round((now - ms) / 1000))
+ if (seconds < 60) return `${seconds}s`
+ if (seconds < 3600) return `${Math.round(seconds / 60)}m`
+ if (seconds < 86_400) return `${Math.round(seconds / 3600)}h`
+ return `${Math.round(seconds / 86_400)}d`
+}
+
+/** Columns, two spaces apart, numbers right-aligned: the shape `harness machines` already uses. */
+function table(deps: SwarmDeps, headers: string[], rows: string[][], numeric: readonly number[] = []): void {
+ const widths = headers.map((head, column) => Math.max(head.length, ...rows.map((row) => (row[column] ?? '').length)))
+ const cell = (value: string, column: number, right: boolean): string => {
+ const padded = right ? value.padStart(widths[column]!) : value.padEnd(widths[column]!)
+ return padded
+ }
+ deps.out(` ${headers.map((head, column) => cell(head, column, numeric.includes(column))).join(' ')}`)
+ for (const row of rows) deps.out(` ${row.map((value, column) => cell(value ?? '', column, numeric.includes(column))).join(' ')}`)
+}
+
+interface Parts {
+ tabId: string
+ head: Json
+ members: Json[]
+ machines: Json[]
+ agents: Json[]
+ groups: Json[]
+ starts: Json[]
+}
+
+function partsOf(root: Json): Parts {
+ return {
+ tabId: text(root.tabId),
+ head: object(object(root.head).data),
+ members: list(root.members).map((row) => object(row.data)),
+ machines: list(root.machines).map((row) => object(row.data)),
+ agents: list(root.agents).map((row) => object(row.data)),
+ groups: list(root.groups).map((row) => object(row.data)),
+ starts: list(root.starts).map((row) => object(row.data)),
+ }
+}
+
+function machineName(parts: Parts, machineId: unknown): string {
+ const row = parts.machines.find((machine) => machine.machineId === machineId)
+ if (!row) return String(machineId ?? 'unknown')
+ const name = text(row.name) || String(machineId)
+ return row.sessionKind === 'team' ? `${name} (team account)` : name
+}
+
+function groupTitle(parts: Parts, conversationId: unknown): string {
+ const group = parts.groups.find((row) => row.id === conversationId)
+ return text(group?.title) || String(conversationId ?? '')
+}
+
+function ownerEmail(parts: Parts, userId: unknown): string {
+ const person = parts.members.find((row) => row.id === userId)
+ return text(person?.email) || String(userId ?? '')
+}
+
+function machineState(machine: Json, now: number): string {
+ const receivedAt = Number(object(machine.observation).receivedAt) || 0
+ if (!receivedAt) return 'never reported'
+ const age = now - receivedAt
+ return age <= LIVE_MS ? 'live' : age <= LATE_MS ? 'late' : 'offline'
+}
+
+async function tabIdOf(deps: SwarmDeps, headers: Record<string, string>, flags: readonly string[]): Promise<string | null> {
+ const inline = flags.find((flag) => flag.startsWith('--tab='))
+ if (inline) return inline.slice('--tab='.length)
+ const at = flags.indexOf('--tab')
+ if (at >= 0) {
+ const next = flags[at + 1]
+ if (next && !next.startsWith('-')) return next
+ }
+ const listing = object(await deps.get('/api/super-tabs/list', headers))
+ return text(list(listing.tabs)[0]?.id) || null
+}
+
+async function partsOfTab(deps: SwarmDeps, headers: Record<string, string>, tabId: string): Promise<Parts> {
+ return partsOf(object(await deps.get(`/api/super-tabs/${encodeURIComponent(tabId)}/parts`, headers)))
+}
+
+/** The start's result, in the words a person reads: running, starting, pending, or why it failed. */
+function startResult(start: Json, now: number): string {
+ const error = text(start.error)
+ if (error) return `failed: ${error} (${ago(Number(start.requestedAt) || now, now)})`
+ if (start.harnessId) return 'running'
+ if (start.dispatched) return `starting (${ago(Number(start.requestedAt) || now, now)})`
+ return `pending (${ago(Number(start.requestedAt) || now, now)})`
+}
+
+export async function swarmCommand(argv: readonly string[], deps: SwarmDeps, json = false): Promise<number> {
+ const words = argv.filter((arg) => !arg.startsWith('-'))
+ const flags = argv.filter((arg) => arg.startsWith('-'))
+ if (!words.length || words[0] === 'help' || flags.includes('-h') || flags.includes('--help')) {
+ deps.out(SWARM_USAGE)
+ return 0
+ }
+ try {
+ return await run(words[0]!, flags, deps, json)
+ } catch (error) {
+ deps.err(`error: ${error instanceof Error ? error.message : String(error)}`)
+ return 1
+ }
+}
+
+async function run(verb: string, flags: readonly string[], deps: SwarmDeps, json: boolean): Promise<number> {
+ const { headers } = await deps.auth()
+ const now = Date.now()
+ const tabId = await tabIdOf(deps, headers, flags)
+ if (!tabId) {
+ if (verb === 'list') { deps.out('No Swarms on this account yet.'); return 0 }
+ deps.out('No Swarm on this account yet.')
+ return 0
+ }
+ if (verb === 'list') {
+ const listing = object(await deps.get('/api/super-tabs/list', headers))
+ const tabs = list(listing.tabs).slice(0, 20)
+ const rows: string[][] = []
+ for (const tab of tabs) {
+ const parts = await partsOfTab(deps, headers, text(tab.id))
+ const running = parts.agents.length
+ const failed = parts.starts.filter((start) => text(start.error)).length
+ rows.push([text(tab.name) || text(tab.id), String(parts.members.length), String(parts.machines.length),
+ `${running} agent${running === 1 ? '' : 's'}${failed ? `, ${failed} failed` : ''}`])
+ }
+ if (json) { deps.out(JSON.stringify(rows)); return 0 }
+ table(deps, ['SWARM', 'PEOPLE', 'MACHINES', 'WORK'], rows, [1, 2])
+ return 0
+ }
+ const parts = await partsOfTab(deps, headers, tabId)
+ const name = text(parts.head.name) || tabId
+ switch (verb) {
+ case 'status': {
+ const running = parts.starts.filter((start) => start.harnessId).length
+ const pending = parts.starts.filter((start) => !start.harnessId && !text(start.error)).length
+ const failed = parts.starts.filter((start) => text(start.error)).length
+ const lead = parts.agents.find((agent) => agent.id && parts.groups.some((group) => group.leadId === agent.id))
+ deps.out(name)
+ deps.out(' ' + '─'.repeat(Math.max(12, name.length)))
+ deps.out(` people ${parts.members.length}`)
+ deps.out(` machines ${parts.machines.length}`)
+ deps.out(` work ${running} running, ${pending} pending, ${failed} failed`)
+ if (lead) deps.out(` lead ${text(lead.displayName) || text(lead.name)} on ${machineName(parts, lead.machineId)}`)
+ deps.out(` updated ${ago(Number(parts.head.lastChangedAt) || now, now)} ago`)
+ return 0
+ }
+ case 'machines': {
+ const rows = parts.machines.map((machine) => [
+ machineName(parts, machine.machineId),
+ ownerEmail(parts, machine.contributorId),
+ list(machine.engines).map((engine) => String(engine)).join(', ') || '-',
+ String(parts.agents.filter((agent) => agent.machineId === machine.machineId).length),
+ machineState(machine, now),
+ ])
+ if (json) { deps.out(JSON.stringify(rows)); return 0 }
+ table(deps, ['MACHINE', 'OWNER', 'ENGINES', 'AGENTS', 'STATE'], rows, [3])
+ return 0
+ }
+ case 'agents': {
+ const rows = parts.agents.map((agent) => [
+ text(agent.displayName) || text(agent.name) || String(agent.id).slice(0, 8),
+ machineName(parts, agent.machineId),
+ text(object(agent.configuration).engine) || 'claude',
+ ])
+ if (json) { deps.out(JSON.stringify(rows)); return 0 }
+ table(deps, ['AGENT', 'MACHINE', 'ENGINE'], rows)
+ return 0
+ }
+ case 'starts': {
+ const rows = parts.starts.map((start) => {
+ const request = object(start.request)
+ return [text(request.name) || String(start.id).slice(0, 8), groupTitle(parts, request.conversationId),
+ machineName(parts, request.machineId), startResult(start, now)]
+ })
+ if (json) { deps.out(JSON.stringify(rows)); return 0 }
+ table(deps, ['START', 'GROUP', 'MACHINE', 'RESULT'], rows)
+ const failed = parts.starts.filter((start) => text(start.error))
+ if (failed.length) {
+ deps.out('')
+ deps.out(' Why it failed')
+ for (const start of failed) deps.out(` ${text(object(start.request).name) || String(start.id).slice(0, 8)}: ${text(start.error)}`)
+ }
+ return 0
+ }
+ default:
+ deps.err(`error: unknown command "swarm ${verb}"\n\n${SWARM_USAGE}`)
+ return 2
+ }
+}
diff --git a/cli/src/team/command.spec.ts b/cli/src/team/command.spec.ts
index 13a797caf..ce4da9224 100644
--- a/cli/src/team/command.spec.ts
+++ b/cli/src/team/command.spec.ts
@@ -91,7 +91,7 @@ describe('harness team', () => {
it('prints its help, and refuses an unknown verb', async () => {
const f = fake()
expect(await teamCommand([], f.deps)).toBe(0)
- expect(f.out[0]).toContain('Usage: harness team <setup | status | model | remove | on | off>')
+ expect(f.out[0]).toContain('Usage: harness team <setup | status | model | logs | sign-in | remove | on | off>')
expect(await teamCommand(['frobnicate'], f.deps)).toBe(2)
})
})
@@ -1008,3 +1008,34 @@ describe('parseLaunchctlPrint', () => {
expect(parseLaunchctlPrint(113, 'Could not find service')).toEqual({ loaded: false, pid: null, state: null })
})
})
+
+describe('harness team logs and sign-in', () => {
+ const config = { version: 1, user: 'harnessteam', realName: 'Harness Team', home: '/Users/harnessteam', owner: 'owner',
+ ownerHome: '/Users/owner', sentinel: '/Users/owner/.harness-team-privacy', port: 18493, label: 'ai.autonomous.harness.team',
+ plist: '/Library/LaunchDaemons/ai.autonomous.harness.team.plist', statusFile: '/Library/Application Support/Harness/Team/status.json',
+ node: '/Users/harnessteam/.harness/runtime/node/bin/node', cli: '/Users/harnessteam/.harness/cli/cli.js', env: {},
+ createdAt: '2026-10-27T10:37:42.635Z' }
+
+ it('reads the team log through the one administrator prompt, and says when there is no account', async () => {
+ const f = fake({ readConfig: () => config as never, adminResult: { ok: true, stdout: '2026-11-03 14:23:01 [agent] create pane open\n' } })
+ expect(await teamCommand(['logs'], f.deps)).toBe(0)
+ expect(f.built[0]!.script).toContain("tail -n 40 '/Users/harnessteam/.harness/cli/data/harness.log'")
+ expect(f.out.join('\n')).toContain('create pane open')
+ const none = fake()
+ expect(await teamCommand(['logs'], none.deps)).toBe(1)
+ expect(none.err.join('\n')).toContain('No Harness Team account')
+ })
+
+ it('refuses the sign-in where it cannot run, naming what to do instead', async () => {
+ const windows = fake({ platform: 'win32', readConfig: () => config as never })
+ expect(await teamCommand(['sign-in', 'claude'], windows.deps)).toBe(1)
+ expect(windows.err.join('\n')).toContain('On Windows, sign in from Harness')
+ const noTerminal = fake({ readConfig: () => config as never, interactive: false })
+ expect(await teamCommand(['sign-in', 'codex'], noTerminal.deps)).toBe(1)
+ expect(noTerminal.err.join('\n')).toContain('Run it in a terminal')
+ const wrong = fake({ readConfig: () => config as never, interactive: true })
+ expect(await teamCommand(['sign-in', 'vim'], wrong.deps)).toBe(1)
+ expect(wrong.err.join('\n')).toContain('Name claude or codex')
+ })
+})
+
diff --git a/cli/src/team/command.ts b/cli/src/team/command.ts
index 6c38775e7..14d41d100 100644
--- a/cli/src/team/command.ts
+++ b/cli/src/team/command.ts
@@ -13,6 +13,7 @@
* Nothing here falls back to the owner: a team account that is missing, signed out or not private is reported, and
* team work does not run as the owner instead.
*/
+import { spawnSync } from 'node:child_process'
import type { AgentTmpState } from '../lib/agentTmp.js'
import { sameSignIn, type AuthSession } from '../lib/authSession.js'
import { SIGN_OUT_BUTTON_FLAG, type SignOutAsked } from '../lib/signOut.js'
@@ -69,7 +70,7 @@ function teamHere(platform: NodeJS.Platform): TeamHere | null {
}
export const TEAM_USAGE = [
- 'Usage: harness team <setup | status | model | remove | on | off> [--json]',
+ 'Usage: harness team <setup | status | model | logs | sign-in | remove | on | off> [--json]',
'',
' setup make the Harness Team account on this Mac, Linux or Windows computer for Swarm work: a separate standard user,',
` "Harness Team" (${TEAM_USER}), whose own Harness daemon runs teammates' agents so they cannot read your files.`,
@@ -78,6 +79,8 @@ export const TEAM_USAGE = [
' status whether the account exists and runs, its sign-in, privacy check and engines, and everything setup made',
' model the team account\'s own model API instead of your subscription: `harness team model set <provider> --model <id>`',
' (asks for the key, hidden; --clear undoes it)',
+ ' logs the team daemon\'s last 40 lines (--lines N): what its agents are doing',
+ ' sign-in sign its Claude Code or Codex in, here in this terminal: harness team sign-in claude',
' remove delete the account, its home folder and its daemon; your home stays private. Run it in Terminal: sudo',
' asks for your password, and macOS asks once to let Terminal administer your computer, which it needs',
' on for a computer used only for agents (a Mac mini, a Linux or Windows box): sign it in for team work',
@@ -201,6 +204,8 @@ export async function teamCommand(argv: string[], deps: TeamCommandDeps): Promis
case 'setup': return await setup(deps, json, flags.includes('--sign-in-again'))
case 'status': return await status(deps, json)
case 'model': return await teamModelSet(deps, words, flags, json)
+ case 'logs': return await teamLogs(deps, words, flags, json)
+ case 'sign-in': return await teamSignIn(deps, words)
case 'remove': return await remove(deps, json)
case 'on': return await teamOn(deps, json, flags.includes('--yes'))
case 'off': return await teamOff(deps, json, flags)
@@ -816,3 +821,64 @@ async function jobStart(deps: TeamCommandDeps, file: string | undefined): Promis
}
return 0
}
+
+/** A POSIX single-quoted word, for the one path the log script names. */
+const quoted = (value: string): string => `'${value.replace(/'/g, `'\\''`)}'`
+
+/**
+ * `harness team logs`: the team daemon's log, which only root can read (it lives in the account's private home).
+ * A server user has no Harness app to open it in, so the command reads it here (headless run, 2026-11-03).
+ */
+async function teamLogs(deps: TeamCommandDeps, words: readonly string[], flags: readonly string[], json: boolean): Promise<number> {
+ const where = deps.platform === 'darwin' ? 'this Mac' : 'this computer'
+ const config = deps.readConfig()
+ if (!config) return fail(deps, json, 'NO_ACCOUNT', `No Harness Team account on ${where}. Run harness team setup first.`)
+ if (deps.platform === 'win32') return fail(deps, json, 'UNSUPPORTED', 'Reading the team log on Windows is not here yet; harness team status shows its path.')
+ const inline = flags.find((flag) => flag.startsWith('--lines='))
+ const asked = inline ? Number(inline.slice('--lines='.length)) : flags.includes('--lines') ? Number(words[1]) : 40
+ const lines = Number.isInteger(asked) && asked > 0 && asked <= 5000 ? asked : 40
+ const result = await deps.admin(() => ({ script: `tail -n ${lines} ${quoted(teamPaths(config.home).log)}` }),
+ `Harness wants to read the Harness Team account's log on ${where}.`)
+ if (!result.ok) {
+ if (result.code === 'NO_PROMPT') deps.err(`✗ ${result.message} Run it in a terminal.`)
+ else if (result.code !== 'CANCELLED') deps.err(`✗ ${result.message}`)
+ return 1
+ }
+ if (json) { deps.out(JSON.stringify({ ok: true, lines })); return 0 }
+ deps.out(result.stdout.replace(/\n$/, ''))
+ return 0
+}
+
+/**
+ * `harness team sign-in [claude|codex]`: the vendor's own sign-in as the team account, in the terminal the person is
+ * already in. On a server there is no Harness app to open a terminal on that account (headless run, 2026-11-03).
+ */
+async function teamSignIn(deps: TeamCommandDeps, words: readonly string[]): Promise<number> {
+ const where = deps.platform === 'darwin' ? 'this Mac' : 'this computer'
+ const config = deps.readConfig()
+ if (!config) return fail(deps, false, 'NO_ACCOUNT', `No Harness Team account on ${where}. Run harness team setup first.`)
+ if (deps.platform === 'win32') {
+ deps.err('✗ On Windows, sign in from Harness: harness team status shows the command for that account.')
+ return 1
+ }
+ if (!deps.interactive) {
+ deps.err('✗ Run it in a terminal: the engine asks its questions there.')
+ return 1
+ }
+ const asked = words[1]
+ if (asked && asked !== 'claude' && asked !== 'codex') {
+ deps.err('✗ Name claude or codex: harness team sign-in claude')
+ return 1
+ }
+ const engine = asked ?? 'claude'
+ const command = engine === 'claude' ? 'claude' : 'codex login --device-auth'
+ deps.out(`Signing ${engine === 'claude' ? 'Claude Code' : 'Codex'} in as ${config.user} (the Harness Team account)...`)
+ const result = spawnSync('sudo', ['-u', config.user, '-H', 'bash', '-lc', command], { stdio: 'inherit' })
+ if (result.status === 0) {
+ deps.out('Signed in. harness team status shows it.')
+ return 0
+ }
+ deps.err('✗ The sign-in did not finish.')
+ return 1
+}
+