Skip to content

Commit 8dc7f98

Browse files
committed
feat(cli): Add Pi to agent start
1 parent b4bdabd commit 8dc7f98

5 files changed

Lines changed: 32 additions & 7 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { AGENTS } from '../../../src/utils/agents.js';
3+
4+
describe('AGENTS', () => {
5+
it('includes Pi as a startable agent', () => {
6+
expect(AGENTS.pi.command).toBe('pi');
7+
expect(AGENTS.pi.matches('pi')).toBe(true);
8+
expect(AGENTS.pi.matches('/usr/local/bin/pi --model x')).toBe(true);
9+
expect(AGENTS.pi.matches('node /repo/feature-pi-adapter/script.js')).toBe(false);
10+
});
11+
});

‎packages/agent-manager/src/utils/agents.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'path';
22
import type { AgentType } from '../adapters/AgentAdapter.js';
33

4-
export type StartableAgentType = Extract<AgentType, 'claude' | 'codex' | 'gemini_cli' | 'opencode'>;
4+
export type StartableAgentType = Extract<AgentType, 'claude' | 'codex' | 'gemini_cli' | 'opencode' | 'pi'>;
55

66
export interface AgentConfig {
77
/** Shell command to launch the agent (sent to tmux via `send-keys`). */
@@ -18,8 +18,9 @@ export interface AgentConfig {
1818
export const AGENTS: Record<StartableAgentType, AgentConfig> = {
1919
claude: { command: 'claude', matches: matchArgv0('claude') },
2020
codex: { command: 'codex', matches: matchArgv0('codex') },
21-
opencode: { command: 'opencode', matches: matchArgv0('opencode') },
2221
gemini_cli: { command: 'gemini', matches: matchAnyToken('gemini') },
22+
opencode: { command: 'opencode', matches: matchArgv0('opencode') },
23+
pi: { command: 'pi', matches: matchAnyBasename(['pi', 'pi.exe', 'pi.js']) },
2324
};
2425

2526
function matchArgv0(name: string): (psCommand: string) => boolean {
@@ -39,3 +40,13 @@ function matchAnyToken(name: string): (psCommand: string) => boolean {
3940
return false;
4041
};
4142
}
43+
44+
function matchAnyBasename(names: string[]): (psCommand: string) => boolean {
45+
const lowers = new Set(names.map((name) => name.toLowerCase()));
46+
return (psCommand) => {
47+
for (const token of psCommand.trim().split(/\s+/)) {
48+
if (lowers.has(path.basename(token).toLowerCase())) return true;
49+
}
50+
return false;
51+
};
52+
}

‎packages/cli/src/__tests__/commands/agent.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ vi.mock('@ai-devkit/agent-manager', () => ({
9696
codex: { command: 'codex', matches: () => true },
9797
gemini_cli: { command: 'gemini', matches: () => true },
9898
opencode: { command: 'opencode', matches: () => true },
99+
pi: { command: 'pi', matches: () => true },
99100
},
100101
RenameNotFoundError: RenameNotFoundError,
101102
RenameConflictError: RenameConflictError,

‎packages/cli/src/__tests__/tui/console/StartAgentPane.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ import {
99

1010
describe('StartAgentPane helpers', () => {
1111
it('lists supported agent start types in pane order', () => {
12-
expect(STARTABLE_AGENT_TYPES).toEqual(['claude', 'codex', 'gemini_cli', 'opencode']);
12+
expect(STARTABLE_AGENT_TYPES).toEqual(['claude', 'codex', 'gemini_cli', 'opencode', 'pi']);
1313
});
1414

1515
it('cycles to the next agent type', () => {
1616
expect(nextStartAgentType('claude')).toBe('codex');
17-
expect(nextStartAgentType('opencode')).toBe('claude');
17+
expect(nextStartAgentType('opencode')).toBe('pi');
18+
expect(nextStartAgentType('pi')).toBe('claude');
1819
});
1920

2021
it('cycles to the previous agent type', () => {
2122
expect(previousStartAgentType('codex')).toBe('claude');
22-
expect(previousStartAgentType('claude')).toBe('opencode');
23+
expect(previousStartAgentType('pi')).toBe('opencode');
24+
expect(previousStartAgentType('claude')).toBe('pi');
2325
});
2426

2527
it('normalizes submitted name and cwd without changing the selected type', () => {

‎packages/cli/src/tui/console/StartAgentPane.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useState } from 'react';
22
import { Box, Text, useInput } from 'ink';
33
import TextInput from 'ink-text-input';
4-
import type { StartableAgentType } from '@ai-devkit/agent-manager';
4+
import { AGENTS, type StartableAgentType } from '@ai-devkit/agent-manager';
55
import { KeyHints, Panel, SectionTitle, TUI_COLORS } from '../design-system/index.js';
66

7-
export const STARTABLE_AGENT_TYPES: StartableAgentType[] = ['claude', 'codex', 'gemini_cli', 'opencode'];
7+
export const STARTABLE_AGENT_TYPES = Object.keys(AGENTS) as StartableAgentType[];
88

99
export function nextStartAgentType(type: StartableAgentType): StartableAgentType {
1010
const index = STARTABLE_AGENT_TYPES.indexOf(type);

0 commit comments

Comments
 (0)