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: restrict tmux agent discovery to harness-managed sessions via session name filtering

0xken1566c4f2704c19
diff --git a/cli/README.md b/cli/README.md
index 8c3bb67c7..b62e3e3eb 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -116,6 +116,10 @@ claude under a terminal backend ──writes──▶ ~/.claude/projects/**.json
configured terminal inventory and one shared process table. A supported top-level engine creates an agent immediately,
before an engine session exists. A changed process in the same pane replaces it immediately; an absent
process is removed after two successful scans. Probe failures do not remove anything.
+- **Only sessions the daemon created are discoverable.** The tmux inventory is limited to sessions
+ named `harness-<engine>-<timestamp>`, which is what `agent_create` names them. A tmux session you
+ open by hand and run an engine in, or one an agent spawns itself with a nested `tmux new-session`,
+ never becomes an agent — create it through the app (or `agent_create`) instead.
- **Hooks bind mutable engine sessions** to the process agent using authenticated tmux and/or Herdr
runtime hints plus verified caller ancestry. Hook socket paths are lookup hints only. They do not
require `MACHINE_ID`. `SessionStart` and catch hooks attach transcript/store metadata; `SessionEnd` only
diff --git a/cli/src/lib/tmuxAgentDiscovery.real.spec.ts b/cli/src/lib/tmuxAgentDiscovery.real.spec.ts
index 63a8cbac1..7a493a12d 100644
--- a/cli/src/lib/tmuxAgentDiscovery.real.spec.ts
+++ b/cli/src/lib/tmuxAgentDiscovery.real.spec.ts
@@ -15,6 +15,11 @@ import {
} from './engineBin.js'
import { TmuxBackend } from './tmuxBackend.js'
import { probeTmuxAgents } from './tmuxAgentDiscovery.js'
+import { HARNESS_SESSION_PREFIX } from './harnessSessionLabel.js'
+
+// Discovery only sees sessions named like agent_create's; a session outside the prefix is
+// invisible to it by design, so every session this suite expects to find must wear it.
+const SESSION_PREFIX = `${HARNESS_SESSION_PREFIX}real-${process.pid}`
const exec = promisify(execFile)
const realDescribe = process.env.RUN_REAL_TMUX_DISCOVERY === '1' ? describe : describe.skip
@@ -63,7 +68,7 @@ realDescribe.sequential('real installed CLI process discovery', () => {
it('creates, notifies, and kills a test-owned session through the shared backend contract', async () => {
const dir = await mkdtemp(join(tmpdir(), 'harness-real-tmux-lifecycle-'))
- const session = `harness-real-${process.pid}-lifecycle`
+ const session = `${SESSION_PREFIX}-lifecycle`
const backend = new TmuxBackend()
createdSessions.add(session)
try {
@@ -90,7 +95,7 @@ realDescribe.sequential('real installed CLI process discovery', () => {
const matrixIt = path ? it : it.skip
matrixIt(`discovers ${engine} once and process-only deletion preserves its pane`, async () => {
const dir = await mkdtemp(join(tmpdir(), `harness-real-${engine}-`))
- const session = `harness-real-${process.pid}-${engine}`
+ const session = `${SESSION_PREFIX}-${engine}`
createdSessions.add(session)
try {
@@ -137,7 +142,7 @@ realDescribe.sequential('real installed CLI process discovery', () => {
it('types literally and submits short text through stdin-loaded buffers', async () => {
const dir = await mkdtemp(join(tmpdir(), 'harness-real-tmux-input-'))
- const session = `harness-real-${process.pid}-input`
+ const session = `${SESSION_PREFIX}-input`
createdSessions.add(session)
try {
await tmux(['new-session', '-d', '-s', session, '-c', dir])
@@ -168,7 +173,7 @@ realDescribe.sequential('real installed CLI process discovery', () => {
it.each(installedAgentAliases)('classifies installed %s alias named agent from its executable identity', async (engine, path) => {
const dir = await mkdtemp(join(tmpdir(), `harness-real-agent-alias-${engine}-`))
- const session = `harness-real-${process.pid}-${engine}-agent-alias`
+ const session = `${SESSION_PREFIX}-${engine}-agent-alias`
createdSessions.add(session)
try {
await tmux(['new-session', '-d', '-s', session, '-c', dir])
diff --git a/cli/src/lib/tmuxAgentDiscovery.ts b/cli/src/lib/tmuxAgentDiscovery.ts
index 02d143dbd..6ae7da897 100644
--- a/cli/src/lib/tmuxAgentDiscovery.ts
+++ b/cli/src/lib/tmuxAgentDiscovery.ts
@@ -16,6 +16,7 @@ import {
import type { AgentEngine } from '../engines/types.js'
import { probeGatewayRuntime } from './gatewayRuntime.js'
import { probeGridAssignment, type GridAssignment } from './gridAssignment.js'
+import { isHarnessSession } from './harnessSessionLabel.js'
import type { ProcessIdentity, RegisteredSession } from './registry.js'
import {
ambiguousAgentProcess,
@@ -105,12 +106,19 @@ export type TmuxPaneInventory =
| { ok: true; panes: TmuxPaneSnapshot[] }
| { ok: false; error: string }
-/** One bounded tmux inventory read, shared by discovery and the neutral backend adapter. */
+/**
+ * One bounded tmux inventory read, shared by discovery and the neutral backend adapter.
+ *
+ * Only panes from sessions this daemon itself named via `agent_create` are returned — a session
+ * the user opened by hand, or one an agent spawned itself with a nested `tmux new-session`, is
+ * invisible to every discovery path (autonomous-harness-desktop#6).
+ */
export async function listTmuxPanes(): Promise<TmuxPaneInventory> {
// Printable delimiters survive tmux's POSIX-locale output sanitiser. Split only the three fixed
// separators so a legitimate `|` in pane_current_path remains part of the path.
const result = await execText('tmux', ['list-panes', '-a', '-F', '#{pane_id}|#{pane_pid}|#{session_name}|#{pane_current_path}'], 2_000)
- return result.ok ? { ok: true, panes: parsePanes(result.stdout) } : result
+ if (!result.ok) return result
+ return { ok: true, panes: parsePanes(result.stdout).filter((pane) => isHarnessSession(pane.tmuxSessionName)) }
}
function childrenByParent(rows: readonly ProcessRow[]): Map<number, ProcessRow[]> {
diff --git a/cli/src/lib/tmuxBackend.ts b/cli/src/lib/tmuxBackend.ts
index 95bfc1e41..4fcb742bf 100644
--- a/cli/src/lib/tmuxBackend.ts
+++ b/cli/src/lib/tmuxBackend.ts
@@ -31,7 +31,6 @@ import {
} from './tmux.js'
import { listTmuxPanes } from './tmuxAgentDiscovery.js'
import { terminalRouteKey } from './terminalRuntime.js'
-import { isHarnessSession } from './harnessSessionLabel.js'
const TMUX_KEYS: Record<TerminalLogicalKey, string> = {
enter: 'Enter',
@@ -230,16 +229,11 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {
if (!result.ok) return { state: 'unavailable', reason: result.error }
return {
state: 'available',
- // Only panes from sessions this daemon itself named via `agent_create` are ever discoverable —
- // a session the user opened by hand, or one an agent spawned itself with a nested
- // `tmux new-session`, never gets surfaced (autonomous-harness-desktop#6).
- roots: result.panes
- .filter((pane) => isHarnessSession(pane.tmuxSessionName))
- .map((pane) => ({
- runtime: { backend: 'tmux' as const, paneId: pane.tmuxPane },
- rootPid: pane.rootPid,
- cwd: pane.cwd,
- })),
+ roots: result.panes.map((pane) => ({
+ runtime: { backend: 'tmux' as const, paneId: pane.tmuxPane },
+ rootPid: pane.rootPid,
+ cwd: pane.cwd,
+ })),
}
}