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.

fix(cli): preserve agent alias process identity

0xken1531294174941a
diff --git a/cli/src/lib/tmux.spec.ts b/cli/src/lib/tmux.spec.ts
index a1da5ad34..be7767ec0 100644
--- a/cli/src/lib/tmux.spec.ts
+++ b/cli/src/lib/tmux.spec.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import type { AgentCommandOwnershipSnapshot } from './engineBin.js'
-import { engineProcessMatchScore, parseProcessRow, resumeSessionId } from './tmux.js'
+import { ambiguousAgentProcess, engineProcessMatchScore, parseProcessRow, resumeSessionId } from './tmux.js'
const ownership = (cursor: string[] = [], grok: string[] = []): AgentCommandOwnershipSnapshot => ({
cursorFileKeys: new Set(cursor),
@@ -44,6 +44,17 @@ describe('tmux process primitives', () => {
expect(engineProcessMatchScore({ executable: 'agent', args: 'agent', imageFileKey: 'same-file' }, 'grok', conflict)).toBe(0)
})
+ it('does not treat a daemon role named agent as the colliding CLI command', () => {
+ expect(ambiguousAgentProcess({
+ executable: '/usr/sbin/distnoted',
+ args: '/usr/sbin/distnoted agent',
+ }, ownership())).toBe(false)
+ expect(ambiguousAgentProcess({
+ executable: '/usr/sbin/cfprefsd',
+ args: '/usr/sbin/cfprefsd agent',
+ }, ownership())).toBe(false)
+ })
+
it('extracts only explicit resume ids', () => {
expect(resumeSessionId('cursor', 'agent --resume=53d3843c-724e-47ff-ae3a-9fedfa328bba'))
.toBe('53d3843c-724e-47ff-ae3a-9fedfa328bba')
diff --git a/cli/src/lib/tmux.ts b/cli/src/lib/tmux.ts
index c9100461b..dff2f52a9 100644
--- a/cli/src/lib/tmux.ts
+++ b/cli/src/lib/tmux.ts
@@ -100,7 +100,7 @@ function hasCursorPackageEntrypoint(args: string): boolean {
function agentAliasCandidate(row: Pick<ProcessRow, 'executable' | 'args'>): boolean {
if (basename(row.executable).toLowerCase() === 'agent') return true
- return argvTokens(row.args).slice(0, 8).some((token) => basename(token).toLowerCase() === 'agent')
+ return basename(processEntrypoint(row.args)).toLowerCase() === 'agent'
}
@@ -148,7 +148,9 @@ async function processRows(): Promise<ProcessRow[] | null> {
function execText(command: string, args: string[], timeout: number): Promise<string | null> {
return new Promise((resolve) => {
- execFile(command, args, { timeout }, (err, stdout) => resolve(err ? null : stdout))
+ // `lsof -p pid1,pid2` exits 1 when even one process disappears or is inaccessible, while still
+ // returning complete records for the surviving PIDs. Keep that usable partial snapshot.
+ execFile(command, args, { timeout }, (err, stdout) => resolve(err && !stdout ? null : stdout))
})
}