feat(agents): add Prime Agent as a supported TUI agent with session history (#12935)

* feat(agents): add Prime Agent as a supported TUI agent with session history

Wire Prime Intellect's prime-agent CLI (a Pi fork) into the desktop and
mobile agent catalogs following the Trae registration pattern, and into
the Agent Session History browser following the OMP pattern:

- types.ts, tui-agent-config.ts: register 'prime-agent' with argv prompt
  injection behind a `--` separator (its own help documents `--` as
  "treat all following arguments as messages"; without it, prompts
  starting with `help`/`agents`/`-…` dispatch as subcommands or
  flags), plus csi-u Shift+Enter encoding matching the Pi TUI it embeds.
- agent-kind.ts, telemetry-events.ts, agent-status-types.ts,
  agent-type-label.ts, tui-agent-display-names.ts,
  tui-agent-selection.ts, skills-cli-agent-keys.ts: standard per-agent
  registrations.
- agent-headless-command.ts: `-p/--print` one-shot runs share the
  print-mode matcher with Claude/Trae so they are not mistaken for live
  interactive panes.
- agent-process-recognition: the npm shim launches a generic bundled
  cli.js, so only the exact package path is an authoritative identity
  (same as Pi and cursor-agent). The three per-agent regex branches are
  now one table in agent-node-entrypoint-identities.ts — the module was
  at its max-lines budget and a table makes the next agent one entry.
- AI Vault: sessions are Pi's message-graph JSONL under
  ~/.prime/agent/sessions (override PRIME_AGENT_CODING_AGENT_DIR —
  Prime Agent brands Pi's env contract instead of sharing
  PI_CODING_AGENT_DIR); parsed by the shared message-graph parser with
  incremental append-resume; discovered locally, in WSL homes, and over
  remote SSH; resumes by absolute transcript path
  (`prime-agent --resume <path>`) like OMP, with session-id fallback.
- skill-discovery-sources.ts: ~/.prime/agent/skills home source.
- Catalog, i18n (en/es/ja/ko/zh), mobile registries, and a bundled
  64x64 favicon (required by mobile's offline-icon invariant).

Scanner-test fixtures for OMP and Prime Agent move into
session-scanner-test-fixtures.ts and the incremental fixture into its
own module, keeping every touched file inside its max-lines budget
without ratchet bumps.

* fix(ai-vault): map custom Prime Agent roots to their sessions child

PRIME_AGENT_CODING_AGENT_DIR is consumed verbatim by the CLI as its agent
config dir, with transcripts always in <agentDir>/sessions — unlike
PI_CODING_AGENT_DIR's <home>/agent/sessions shape the shared normalizer
models. A custom root with a non-special basename (or a `.prime` leaf)
was therefore scanned as-is instead of its sessions child. Dedicated
normalizePrimeAgentSessionsDir appends `sessions` to every configured
root, taking only an explicit `.../sessions` path as-is; the shared
Pi/OMP normalizer drops the `.prime` widening it no longer needs.

Raised in review on #12935.

* fix(ai-vault): guard degenerate Prime Agent roots and cover the remote source

normalizePrimeAgentSessionsDir stripped a filesystem-root value ('/' or '//')
to '', which then joined into the relative root 'sessions' and would walk the
main-process cwd. session-scanner-roots.ts already carries this guard for the
OMP variant; apply the same fallback here.

The remote SSH source had no test: deleting jsonlSource('prime-agent', ...)
left the suite green, unlike the local path which is pinned by the
AI_VAULT_AGENTS exhaustiveness assertion in session-scanner.test.ts. Add a
case that fixes the .prime/agent/sessions root segments, the .jsonl
extension, and parser routing.

Raised in review on #12935.

* fix(ai-vault): honor Prime Agent's sessions-root env and non-interactive modes

Verified against upstream PrimeIntellect-ai/prime-agent source rather than
inferred from the CLI's help text.

config.ts getSessionsDir() reads PRIME_AGENT_SESSION_DIR (and its legacy
PRIME_AGENT_CODING_AGENT_SESSION_DIR alias) ahead of the agent dir and uses it
verbatim; setting either left the vault silently empty. It also appends
`sessions` to the agent dir unconditionally, with no basename escape hatch, so
PRIME_AGENT_CODING_AGENT_DIR=/data/sessions writes to /data/sessions/sessions
while Orca scanned /data/sessions. getAgentDir() and the session-dir override
both run through expandTildePath, so a `~` value set outside a shell resolves.

cli/args.ts also spells the non-interactive runs `--mode json|rpc|acp|daemon`,
which the shared print-mode matcher does not know, so those panes were counted
as live interactive agents and the paste-submit path would write user text into
a JSON-RPC/ACP stream. Match upstream exactly: only the space-separated form,
since `--mode=json` is not parsed by the CLI and does start the TUI.

Raised in review on #12935.

* fix(ai-vault): keep Prime Agent roots absolute and remote segments posix

Two holes in the previous commit.

The degenerate-root guard only rejected pure-separator values, so a relative
env value still resolved against the main-process cwd:
PRIME_AGENT_CODING_AGENT_DIR='.' scanned '<cwd>/sessions' and, worse,
PRIME_AGENT_SESSION_DIR='.' scanned the cwd itself. Require an absolute path in
both branches and fall back to the default otherwise.

remotePrimeAgentSessionsSegments() built its segments with the local-platform
join, so on a Windows client scanning a posix SSH host it produced
'\.prime\agent\sessions' and split('/') collapsed it to one bogus segment —
remote discovery would have found nothing. Remote roots are posix regardless of
client platform, so keep them literal. Pi and OMP are unaffected: their
normalizer returns a '.../sessions' input unchanged and never joins.

Raised in review on #12935.

* test(ai-vault): pin Windows drive roots to the Prime Agent default fallback

'C:\' and 'C:/' strip to the drive-relative 'C:', which isAbsolute
rejects on every platform — assert they land in the default fallback so
a looser truthiness check can't reintroduce a 'C:sessions' scan root.

Raised in review on #12935.

* test(ai-vault): pin the drive-relative root form and state what the posix runner can assert

---------

Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
This commit is contained in:
Evgenii
2026-08-09 14:50:02 -07:00
committed by GitHub
co-authored by Brennan Benson
parent 45c1cb979a
commit 63af0bdd24
47 changed files with 624 additions and 71 deletions
+4 -1
View File
@@ -1,14 +1,17 @@
import { isAnteHeadlessOneShotCommand } from './ante-headless-command'
import { isPrimeAgentHeadlessOneShotCommand } from './prime-agent-headless-command'
import { isPrintModeHeadlessOneShotCommand } from './print-mode-headless-command'
import type { TuiAgent } from './types'
// Why: a table (not an if-chain) so adding an agent is one entry; Claude and Trae share
// the same `--print` one-shot contract, Ante's `--prompt` form needs its own matcher.
// the same `--print` one-shot contract, Ante's `--prompt` form and Prime Agent's
// `--mode` forms need their own matchers.
const HEADLESS_ONE_SHOT_MATCHERS: Partial<
Record<TuiAgent, (tokens: readonly string[]) => boolean>
> = {
claude: isPrintModeHeadlessOneShotCommand,
trae: isPrintModeHeadlessOneShotCommand,
'prime-agent': isPrimeAgentHeadlessOneShotCommand,
ante: isAnteHeadlessOneShotCommand
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

+1
View File
@@ -23,6 +23,7 @@ const TUI_AGENT_KIND_BY_AGENT = {
'mimo-code': 'mimo-code',
pi: 'pi',
omp: 'omp',
'prime-agent': 'prime-agent',
gemini: 'gemini',
antigravity: 'antigravity',
aider: 'aider',
@@ -0,0 +1,30 @@
import type { TuiAgent } from './types'
// Node CLIs whose shims launch a generic script (cli.js, versioned index.js), so
// only the exact install path is an authoritative identity signal.
export const EXACT_NODE_ENTRYPOINT_IDENTITIES: readonly {
pattern: RegExp
agent: TuiAgent
processName: string
}[] = [
// Why: Cursor's native Windows launcher runs a generic versioned index.js,
// so its install path is the only stable identity that avoids ordinary Node apps.
{
pattern: /(?:^|\/)cursor-agent\/versions\/[^/]+\/index\.js$/,
agent: 'cursor',
processName: 'cursor-agent'
},
// Why: Pi's npm shim launches a generic cli.js; only the exact package path is authoritative.
{
pattern:
/(?:^|\/)node_modules\/@(?:earendil-works|mariozechner)\/pi-coding-agent\/dist\/cli\.js$/,
agent: 'pi',
processName: 'pi'
},
// Why: same shape as Pi — Prime Agent's npm shim launches a generic bundled cli.js.
{
pattern: /(?:^|\/)node_modules\/prime-agent\/dist\/bundle\/cli\.js$/,
agent: 'prime-agent',
processName: 'prime-agent'
}
]
@@ -242,6 +242,61 @@ describe('agent process recognition', () => {
).toEqual({ agent: 'pi', processName: 'pi' })
})
it('recognizes Prime Agent by its binary and npm entrypoint', () => {
expect(recognizeAgentProcess('prime-agent')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
expect(recognizeAgentProcess('/opt/homebrew/bin/prime-agent')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
expect(
recognizeAgentProcessFromCommandLine(
'node /opt/homebrew/lib/node_modules/prime-agent/dist/bundle/cli.js'
)
).toEqual({ agent: 'prime-agent', processName: 'prime-agent' })
expect(
recognizeAgentProcessFromCommandLine(
String.raw`node.exe C:\Users\dev\AppData\Roaming\npm\node_modules\prime-agent\dist\bundle\cli.js`
)
).toEqual({ agent: 'prime-agent', processName: 'prime-agent' })
})
it('does not recognize Prime Agent headless one-shot commands as interactive agents', () => {
expect(recognizeAgentProcessFromCommandLine('prime-agent -p "summarize this diff"')).toBeNull()
expect(recognizeAgentProcessFromCommandLine('prime-agent --print "review this"')).toBeNull()
expect(recognizeAgentProcessFromCommandLine('prime-agent --resume abc123')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
// Why: past `--` nothing is a flag, so this is the interactive pane Orca itself launches.
expect(
recognizeAgentProcessFromCommandLine('prime-agent -- "--print the release notes"')
).toEqual({ agent: 'prime-agent', processName: 'prime-agent' })
})
it('does not recognize Prime Agent non-interactive --mode runs as interactive agents', () => {
for (const mode of ['json', 'rpc', 'acp', 'daemon']) {
expect(recognizeAgentProcessFromCommandLine(`prime-agent --mode ${mode}`)).toBeNull()
}
// Why: `text` is the interactive TUI mode Orca hosts.
expect(recognizeAgentProcessFromCommandLine('prime-agent --mode text')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
// Why: the CLI only parses `--mode <value>` as separate tokens, so `--mode=json`
// is ignored by it and still starts the interactive mode.
expect(recognizeAgentProcessFromCommandLine('prime-agent --mode=json')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
expect(recognizeAgentProcessFromCommandLine('prime-agent -- --mode rpc')).toEqual({
agent: 'prime-agent',
processName: 'prime-agent'
})
})
it('recognizes only the agent subcommand of the generic Orca CLI', () => {
expect(recognizeAgentProcessFromCommandLine('orca claude-teams')).toEqual({
agent: 'claude-agent-teams',
+5 -11
View File
@@ -1,4 +1,5 @@
import { getTuiAgentDetectCommands, TUI_AGENT_CONFIG } from './tui-agent-config'
import { EXACT_NODE_ENTRYPOINT_IDENTITIES } from './agent-node-entrypoint-identities'
import type { AgentType } from './agent-status-types'
import type { TuiAgent } from './types'
import { filterHeadlessOneShotAgentCommand } from './agent-headless-command'
@@ -52,9 +53,6 @@ const NODE_PACKAGE_SCRIPT_ENTRYPOINTS: Record<string, readonly string[]> = {
codex: ['node_modules/@openai/codex/'],
gemini: ['node_modules/@google/gemini-cli/']
}
const CURSOR_AGENT_NODE_ENTRYPOINT_RE = /(?:^|\/)cursor-agent\/versions\/[^/]+\/index\.js$/
const PI_AGENT_NODE_ENTRYPOINT_RE =
/(?:^|\/)node_modules\/@(?:earendil-works|mariozechner)\/pi-coding-agent\/dist\/cli\.js$/
const PYTHON_SCRIPT_ENTRYPOINT_DIRECTORIES = ['/bin/', '/scripts/', '/site-packages/']
const PROCESS_TO_AGENT = new Map<string, TuiAgent>()
@@ -206,14 +204,10 @@ function comparablePath(token: string): string {
function recognizeNodeScriptEntrypoint(token: string): RecognizedAgentProcess | null {
const path = comparablePath(token)
// Why: Cursor's native Windows launcher runs a generic versioned index.js,
// so its install path is the only stable identity that avoids ordinary Node apps.
if (CURSOR_AGENT_NODE_ENTRYPOINT_RE.test(path)) {
return { agent: 'cursor', processName: 'cursor-agent' }
}
// Why: Pi's npm shim launches a generic cli.js; only the exact package path is authoritative.
if (PI_AGENT_NODE_ENTRYPOINT_RE.test(path)) {
return { agent: 'pi', processName: 'pi' }
for (const identity of EXACT_NODE_ENTRYPOINT_IDENTITIES) {
if (identity.pattern.test(path)) {
return { agent: identity.agent, processName: identity.processName }
}
}
const normalized = normalizeProcessName(token, { stripInterpreterScriptExtension: true })
const markers = NODE_PACKAGE_SCRIPT_ENTRYPOINTS[normalized]
+1
View File
@@ -31,6 +31,7 @@ export type WellKnownAgentType =
| 'aider'
| 'pi'
| 'omp'
| 'prime-agent'
| 'droid'
| 'command-code'
| 'grok'
+1
View File
@@ -16,6 +16,7 @@ const WELL_KNOWN_LABELS: Record<string, string> = {
aider: 'Aider',
pi: 'Pi',
omp: 'OMP',
'prime-agent': 'Prime Agent',
droid: 'Droid',
'command-code': 'Command Code',
grok: 'Grok',
@@ -122,4 +122,31 @@ describe('buildAiVaultResumeCommand', () => {
})
).toBe("cd '/Users/ada/repo' && omp --resume '019f27cd-4268-7000-96e7-62f42a55c144'")
})
it('resumes Prime Agent by absolute transcript path like OMP', () => {
expect(
buildAiVaultResumeCommand({
agent: 'prime-agent',
sessionId: 'dddddddd-eeee-4fff-8aaa-111111111111',
resumeFilePath:
'/Users/ada/.prime/agent/sessions/dddddddd-eeee-4fff-8aaa-111111111111.jsonl',
cwd: '/Users/ada/repo',
platform: 'darwin'
})
).toBe(
"cd '/Users/ada/repo' && prime-agent --resume '/Users/ada/.prime/agent/sessions/dddddddd-eeee-4fff-8aaa-111111111111.jsonl'"
)
})
it('falls back to the session id when no Prime Agent transcript path is known', () => {
expect(
buildAiVaultResumeCommand({
agent: 'prime-agent',
sessionId: 'dddddddd-eeee-4fff-8aaa-111111111111',
resumeFilePath: null,
cwd: '/Users/ada/repo',
platform: 'darwin'
})
).toBe("cd '/Users/ada/repo' && prime-agent --resume 'dddddddd-eeee-4fff-8aaa-111111111111'")
})
})
+13 -7
View File
@@ -22,11 +22,15 @@ export function buildAiVaultResumeCommand(args: {
const { agent, sessionId, cwd, platform, commandOverride, codexHome, resumeFilePath, shell } =
args
const baseCommand = commandOverride?.trim() || defaultAiVaultResumeCommandBase(agent)
// Why: OMP's `--resume` accepts an absolute transcript path, which resolves
// regardless of which session-dir root (custom OMP_CODING_AGENT_DIR / WSL
// home) the file was discovered under, where an id-prefix lookup scoped to
// the default store would miss it. Falls back to the id if no path is known.
const resumeTarget = agent === 'omp' && resumeFilePath?.trim() ? resumeFilePath.trim() : sessionId
// Why: OMP's and Prime Agent's `--resume` accept an absolute transcript path,
// which resolves regardless of which session-dir root (custom
// OMP_CODING_AGENT_DIR / PRIME_AGENT_CODING_AGENT_DIR / WSL home) the file was
// discovered under, where an id-prefix lookup scoped to the default store
// would miss it. Falls back to the id if no path is known.
const resumeTarget =
(agent === 'omp' || agent === 'prime-agent') && resumeFilePath?.trim()
? resumeFilePath.trim()
: sessionId
const sessionArg =
shell === 'cmd'
? quoteWindowsCmdArg(resumeTarget)
@@ -167,10 +171,12 @@ function buildAgentResumeInvocation(
case 'devin':
case 'openclaw':
case 'droid':
// Why: OMP resumes by absolute transcript path (see buildAiVaultResumeCommand),
// but the `--resume <arg>` invocation form is identical to the others here.
// Why: OMP and Prime Agent resume by absolute transcript path (see
// buildAiVaultResumeCommand), but the `--resume <arg>` invocation form is
// identical to the others here.
// falls through
case 'omp':
case 'prime-agent':
return `${baseCommand} --resume ${sessionArg}`
case 'antigravity':
return `${baseCommand} --conversation ${sessionArg}`
+2
View File
@@ -7,6 +7,7 @@ export const AI_VAULT_AGENTS = [
'hermes',
'pi',
'omp',
'prime-agent',
'cursor',
'gemini',
'antigravity',
@@ -47,6 +48,7 @@ export const AI_VAULT_AGENT_LABELS = {
hermes: 'Hermes',
pi: 'Pi',
omp: 'OMP',
'prime-agent': 'Prime Agent',
cursor: 'Cursor',
gemini: 'Gemini',
antigravity: 'Antigravity',
@@ -0,0 +1,22 @@
import { isPrintModeHeadlessOneShotCommand } from './print-mode-headless-command'
// Why: Prime Agent's non-interactive runs are `--mode <json|rpc|acp|daemon>` as well as
// `--print`; only `text` hosts the TUI. Matching upstream, the value must be a separate
// token — `--mode=json` is not parsed by the CLI, so it still starts the interactive mode.
const NON_INTERACTIVE_MODES = new Set(['json', 'rpc', 'acp', 'daemon'])
export function isPrimeAgentHeadlessOneShotCommand(tokens: readonly string[]): boolean {
if (isPrintModeHeadlessOneShotCommand(tokens)) {
return true
}
for (let index = 1; index < tokens.length; index += 1) {
// Why: `--` ends option parsing, so a prompt that reads like `--mode` is still a prompt.
if (tokens[index] === '--') {
return false
}
if (tokens[index] === '--mode' && NON_INTERACTIVE_MODES.has(tokens[index + 1] ?? '')) {
return true
}
}
return false
}
+1
View File
@@ -22,6 +22,7 @@ export const SKILLS_CLI_AGENT_KEY_BY_TUI_AGENT = {
'mimo-code': null,
pi: 'pi',
omp: null,
'prime-agent': null,
gemini: 'gemini-cli',
antigravity: 'antigravity',
aider: null,
+1
View File
@@ -77,6 +77,7 @@ export const AGENT_KIND_VALUES = [
'mimo-code',
'pi',
'omp',
'prime-agent',
'gemini',
'antigravity',
'aider',
+12
View File
@@ -144,6 +144,18 @@ export const TUI_AGENT_CONFIG: Record<TuiAgent, TuiAgentConfig> = {
promptInjectionMode: 'argv',
draftPromptEnvVar: 'ORCA_OMP_PREFILL'
},
'prime-agent': {
detectCmd: 'prime-agent',
launchCmd: 'prime-agent',
expectedProcess: 'prime-agent',
// Why: `prime-agent [options] [@files...] [message...]` takes the task as positional argv.
promptInjectionMode: 'argv',
// Why: separator so prompts starting with `help`/`agents`/`-…` aren't parsed as a
// subcommand or flag — its help documents `--` as "treat all following arguments as messages".
argvPromptSeparator: '--',
// Why: Prime Agent embeds Pi's TUI and decodes CSI-u the same way (see pi above).
windowsShiftEnterEncoding: 'csi-u'
},
gemini: {
detectCmd: 'gemini',
launchCmd: 'gemini',
+1
View File
@@ -18,6 +18,7 @@ export const TUI_AGENT_DISPLAY_NAMES: Record<TuiAgent, string> = {
'mimo-code': 'MiMo Code',
pi: 'Pi',
omp: 'OMP',
'prime-agent': 'Prime Agent',
gemini: 'Gemini',
antigravity: 'Antigravity',
aider: 'Aider',
+1
View File
@@ -16,6 +16,7 @@ export const TUI_AGENT_AUTO_PICK_ORDER = [
'trae',
'pi',
'omp',
'prime-agent',
'gemini',
'antigravity',
'aider',
+1
View File
@@ -2626,6 +2626,7 @@ export type TuiAgent =
| 'devin' // Devin CLI
| 'ante' // Ante (Antigma Labs)
| 'trae' // Trae CLI
| 'prime-agent' // Prime Agent (Prime Intellect)
export type TaskViewPresetId = 'all' | 'issues' | 'review' | 'my-issues' | 'my-prs' | 'prs'