Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "1.0.13",
"version": "1.0.14",
"type": "module",
"bin": {
"spawn": "cli.js"
Expand Down
18 changes: 16 additions & 2 deletions packages/cli/src/commands/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,28 @@ const KNOWN_AGENTS = [
"kilocode",
"hermes",
"junie",
"pi",
"cursor",
] as const;
type KnownAgent = (typeof KNOWN_AGENTS)[number];

/** Map manifest agent key → CLI binary name (only where they differ). */
const AGENT_BINARY: Partial<Record<KnownAgent, string>> = {
cursor: "agent",
};

/** Get the CLI binary name for an agent (defaults to the agent key itself). */
function agentBinary(agent: KnownAgent): string {
return AGENT_BINARY[agent] ?? agent;
}

/** Auto-detect which agent is installed/running on the remote host. */
function detectAgent(host: string, user: string, keyOpts: string[], runCmd: SshCommandFn): string | null {
// First: check running processes
// Note: cursor's binary is "agent" which is too generic for ps grep, so it's
// detected only via the installed-binary check below.
const psCmd =
"ps aux 2>/dev/null | grep -oE 'claude(-code)?|openclaw|codex|opencode|kilocode|hermes|junie' | grep -v grep | head -1 || true";
"ps aux 2>/dev/null | grep -oE 'claude(-code)?|openclaw|codex|opencode|kilocode|hermes|junie|pi' | grep -v grep | head -1 || true";
const psOut = runCmd(host, user, keyOpts, psCmd);
if (psOut) {
const match = KNOWN_AGENTS.find((b: KnownAgent) => psOut.includes(b));
Expand All @@ -89,7 +103,7 @@ function detectAgent(host: string, user: string, keyOpts: string[], runCmd: SshC

// Second: check installed binaries — one SSH call per agent to avoid shell injection
for (const agent of KNOWN_AGENTS) {
const whichOut = runCmd(host, user, keyOpts, `command -v ${agent}`);
const whichOut = runCmd(host, user, keyOpts, `command -v ${agentBinary(agent)}`);
if (whichOut) {
return agent;
}
Expand Down
Loading