Add Claude Agent Teams native pane launcher (#4892)
* Add Claude Agent Teams native pane launcher Co-authored-by: Orca <help@stably.ai> * Fix Agent Teams CI coverage checks Co-authored-by: Orca <help@stably.ai> * Fix Claude Agent Teams split direction mapping Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -15,6 +15,7 @@ type ConcreteAgentKind = Exclude<AgentKind, 'other'>
|
||||
|
||||
const TUI_AGENT_KIND_BY_AGENT = {
|
||||
claude: 'claude-code',
|
||||
'claude-agent-teams': 'claude-agent-teams',
|
||||
openclaude: 'openclaude',
|
||||
codex: 'codex',
|
||||
autohand: 'autohand',
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
addClaudeTeammateModeAuto,
|
||||
isDirectClaudeCommand,
|
||||
parseTmuxArgs,
|
||||
renderTmuxFormat,
|
||||
splitTmuxCommand,
|
||||
tmuxSendKeysText,
|
||||
tmuxValue
|
||||
} from './claude-agent-teams-tmux-compat'
|
||||
|
||||
describe('claude agent teams tmux compat primitives', () => {
|
||||
it('parses clustered tmux flags and keeps split size out of positional command text', () => {
|
||||
const parsed = parseTmuxArgs(
|
||||
['-t', '%1', '-hPl', '70%', '-F', '#{pane_id}', 'echo hi'],
|
||||
['-t', '-l', '-F'],
|
||||
['-h', '-P', '-d']
|
||||
)
|
||||
|
||||
expect(parsed.flags.has('-h')).toBe(true)
|
||||
expect(parsed.flags.has('-P')).toBe(true)
|
||||
expect(tmuxValue(parsed, '-l')).toBe('70%')
|
||||
expect(tmuxValue(parsed, '-F')).toBe('#{pane_id}')
|
||||
expect(parsed.positional).toEqual(['echo hi'])
|
||||
})
|
||||
|
||||
it('recognizes top-level tmux version probes separately from subcommand flags', () => {
|
||||
expect(splitTmuxCommand(['-V'])).toEqual({ command: '-V', args: [] })
|
||||
expect(splitTmuxCommand(['split-window', '-v'])).toEqual({
|
||||
command: 'split-window',
|
||||
args: ['-v']
|
||||
})
|
||||
})
|
||||
|
||||
it('renders supported tmux format variables and removes unknown variables', () => {
|
||||
expect(
|
||||
renderTmuxFormat(
|
||||
'#{session_name}:#{window_index}:#{missing}',
|
||||
{
|
||||
session_name: 'orca',
|
||||
window_index: '0'
|
||||
},
|
||||
'fallback'
|
||||
)
|
||||
).toBe('orca:0:')
|
||||
})
|
||||
|
||||
it('maps send-keys tokens using practical tmux semantics', () => {
|
||||
expect(tmuxSendKeysText(['hello', 'Space', 'world', 'Enter'], false)).toBe('hello world\r')
|
||||
expect(tmuxSendKeysText(['hello', 'Space', 'world'], true)).toBe('hello Space world')
|
||||
})
|
||||
|
||||
it('only rewrites direct Claude launch commands', () => {
|
||||
expect(isDirectClaudeCommand("claude 'fix it'")).toBe(true)
|
||||
expect(isDirectClaudeCommand("echo ok; claude 'fix it'")).toBe(false)
|
||||
expect(addClaudeTeammateModeAuto("claude 'fix it'")).toBe(
|
||||
"claude --teammate-mode auto 'fix it'"
|
||||
)
|
||||
expect(addClaudeTeammateModeAuto('claude --teammate-mode in-process')).toBe(
|
||||
'claude --teammate-mode in-process'
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,193 @@
|
||||
export type ClaudeAgentTeamsMode = 'off' | 'in-process' | 'native-panes-shim'
|
||||
|
||||
export type ParsedTmuxCommand = {
|
||||
command: string
|
||||
args: string[]
|
||||
}
|
||||
|
||||
export type ParsedTmuxArgs = {
|
||||
flags: Set<string>
|
||||
values: Map<string, string[]>
|
||||
positional: string[]
|
||||
}
|
||||
|
||||
const TMUX_FORMAT_VAR_RE = /#\{[^}]+\}/g
|
||||
|
||||
export function splitTmuxCommand(argv: string[]): ParsedTmuxCommand {
|
||||
const globalValueFlags = new Set(['-L', '-S', '-f'])
|
||||
const globalBoolFlags = new Set(['-V', '-v'])
|
||||
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const arg = argv[i] ?? ''
|
||||
if (arg === '--') {
|
||||
break
|
||||
}
|
||||
if (!arg.startsWith('-') || arg === '-') {
|
||||
return { command: arg.toLowerCase(), args: argv.slice(i + 1) }
|
||||
}
|
||||
if (globalBoolFlags.has(arg)) {
|
||||
return { command: arg, args: [] }
|
||||
}
|
||||
if (globalValueFlags.has(arg)) {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('tmux shim requires a command')
|
||||
}
|
||||
|
||||
export function parseTmuxArgs(
|
||||
args: string[],
|
||||
valueFlags: string[],
|
||||
boolFlags: string[]
|
||||
): ParsedTmuxArgs {
|
||||
const valueSet = new Set(valueFlags)
|
||||
const boolSet = new Set(boolFlags)
|
||||
const flags = new Set<string>()
|
||||
const values = new Map<string, string[]>()
|
||||
const positional: string[] = []
|
||||
let pastTerminator = false
|
||||
|
||||
for (let i = 0; i < args.length; i += 1) {
|
||||
const arg = args[i] ?? ''
|
||||
if (pastTerminator) {
|
||||
positional.push(arg)
|
||||
continue
|
||||
}
|
||||
if (arg === '--') {
|
||||
pastTerminator = true
|
||||
continue
|
||||
}
|
||||
if (!arg.startsWith('-') || arg === '-' || arg.startsWith('--')) {
|
||||
positional.push(arg)
|
||||
continue
|
||||
}
|
||||
|
||||
const cluster = arg.slice(1)
|
||||
let cursor = 0
|
||||
let recognized = false
|
||||
while (cursor < cluster.length) {
|
||||
const flag = `-${cluster[cursor]}`
|
||||
if (boolSet.has(flag)) {
|
||||
flags.add(flag)
|
||||
cursor += 1
|
||||
recognized = true
|
||||
continue
|
||||
}
|
||||
if (valueSet.has(flag)) {
|
||||
const remainder = cluster.slice(cursor + 1)
|
||||
const value = remainder || args[++i] || ''
|
||||
values.set(flag, [...(values.get(flag) ?? []), value])
|
||||
recognized = true
|
||||
cursor = cluster.length
|
||||
continue
|
||||
}
|
||||
recognized = false
|
||||
break
|
||||
}
|
||||
if (!recognized) {
|
||||
positional.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
return { flags, values, positional }
|
||||
}
|
||||
|
||||
export function tmuxValue(parsed: ParsedTmuxArgs, flag: string): string | undefined {
|
||||
return parsed.values.get(flag)?.at(-1)
|
||||
}
|
||||
|
||||
export function renderTmuxFormat(
|
||||
format: string | undefined,
|
||||
context: Record<string, string>,
|
||||
fallback: string
|
||||
): string {
|
||||
if (!format) {
|
||||
return fallback
|
||||
}
|
||||
let rendered = format
|
||||
for (const [key, value] of Object.entries(context)) {
|
||||
rendered = rendered.replaceAll(`#{${key}}`, value)
|
||||
}
|
||||
rendered = rendered.replace(TMUX_FORMAT_VAR_RE, '').trim()
|
||||
return rendered || fallback
|
||||
}
|
||||
|
||||
export function tmuxSendKeysText(tokens: string[], literal: boolean): string {
|
||||
if (literal) {
|
||||
return tokens.join(' ')
|
||||
}
|
||||
let result = ''
|
||||
let pendingSpace = false
|
||||
for (const token of tokens) {
|
||||
const special = tmuxSpecialKeyText(token)
|
||||
if (special !== null) {
|
||||
result += special
|
||||
pendingSpace = false
|
||||
continue
|
||||
}
|
||||
if (pendingSpace) {
|
||||
result += ' '
|
||||
}
|
||||
result += token
|
||||
pendingSpace = true
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function tmuxSpecialKeyText(token: string): string | null {
|
||||
switch (token.toLowerCase()) {
|
||||
case 'enter':
|
||||
case 'c-m':
|
||||
case 'kpenter':
|
||||
return '\r'
|
||||
case 'tab':
|
||||
case 'c-i':
|
||||
return '\t'
|
||||
case 'space':
|
||||
return ' '
|
||||
case 'bspace':
|
||||
case 'backspace':
|
||||
return '\x7f'
|
||||
case 'escape':
|
||||
case 'esc':
|
||||
case 'c-[':
|
||||
return '\x1b'
|
||||
case 'c-c':
|
||||
return '\x03'
|
||||
case 'c-d':
|
||||
return '\x04'
|
||||
case 'c-z':
|
||||
return '\x1a'
|
||||
case 'c-l':
|
||||
return '\x0c'
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function isDirectClaudeCommand(command: string | undefined): boolean {
|
||||
const trimmed = command?.trim() ?? ''
|
||||
if (!trimmed) {
|
||||
return false
|
||||
}
|
||||
if (/[;&|<>`]/.test(trimmed)) {
|
||||
return false
|
||||
}
|
||||
const first = trimmed.match(/^\S+/)?.[0] ?? ''
|
||||
return first === 'claude' || first.endsWith('/claude')
|
||||
}
|
||||
|
||||
export function addClaudeTeammateModeAuto(command: string): string {
|
||||
if (/(^|\s)--teammate-mode(?:\s|=|$)/.test(command)) {
|
||||
return command
|
||||
}
|
||||
return command.replace(/^(\S+)/, '$1 --teammate-mode auto')
|
||||
}
|
||||
|
||||
export function addClaudeTeammateModeInProcess(command: string): string {
|
||||
if (/(^|\s)--teammate-mode(?:\s|=|$)/.test(command)) {
|
||||
return command
|
||||
}
|
||||
return command.replace(/^(\S+)/, '$1 --teammate-mode in-process')
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import { getDefaultSourceControlAiSettings } from './source-control-ai'
|
||||
import { DEFAULT_APP_ICON_ID } from './app-icon'
|
||||
import { DEFAULT_OPEN_IN_APPLICATIONS } from './open-in-applications'
|
||||
import { DEFAULT_BROWSER_PAGE_ZOOM_LEVEL } from './browser-page-zoom'
|
||||
import { DEFAULT_DISABLED_TUI_AGENTS } from './tui-agent-selection'
|
||||
|
||||
export { DEFAULT_STATUS_BAR_ITEMS } from './status-bar-defaults'
|
||||
export {
|
||||
@@ -233,6 +234,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
|
||||
windowBackgroundBlur: false,
|
||||
terminalClipboardOnSelect: false,
|
||||
terminalAllowOsc52Clipboard: false,
|
||||
claudeAgentTeamsMode: 'off',
|
||||
setupScriptLaunchMode: 'new-tab',
|
||||
terminalScrollbackBytes: 10_000_000,
|
||||
httpProxyUrl: '',
|
||||
@@ -269,7 +271,8 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
|
||||
activeClaudeManagedAccountId: null,
|
||||
terminalScopeHistoryByWorktree: true,
|
||||
defaultTuiAgent: null,
|
||||
disabledTuiAgents: [],
|
||||
disabledTuiAgents: [...DEFAULT_DISABLED_TUI_AGENTS],
|
||||
claudeAgentTeamsDefaultDisabledMigrated: true,
|
||||
skipDeleteWorktreeConfirm: false,
|
||||
skipDeleteAutomationConfirm: false,
|
||||
defaultTaskViewPreset: 'all',
|
||||
|
||||
@@ -58,6 +58,7 @@ import type {
|
||||
// should map to concrete values; see `tuiAgentToAgentKind`.
|
||||
export const AGENT_KIND_VALUES = [
|
||||
'claude-code',
|
||||
'claude-agent-teams',
|
||||
'openclaude',
|
||||
'codex',
|
||||
'autohand',
|
||||
|
||||
@@ -69,6 +69,16 @@ export const TUI_AGENT_CONFIG: Record<TuiAgent, TuiAgentConfig> = {
|
||||
// See PR https://github.com/stablyai/orca/pull/926 for context.
|
||||
draftPromptFlag: '--prefill'
|
||||
},
|
||||
'claude-agent-teams': {
|
||||
// Why: this is an Orca-provided launch mode, not a separate upstream
|
||||
// binary. Detection follows the Orca CLI, while the wrapper validates the
|
||||
// real Claude binary when it starts.
|
||||
detectCmd: 'orca',
|
||||
detectCmdAliases: ['orca-dev', 'orca-ide'],
|
||||
launchCmd: 'orca claude-teams',
|
||||
expectedProcess: 'claude',
|
||||
promptInjectionMode: 'stdin-after-start'
|
||||
},
|
||||
openclaude: {
|
||||
detectCmd: 'openclaude',
|
||||
launchCmd: 'openclaude',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { isTuiAgent } from './tui-agent-config'
|
||||
// automatic fallback priority when the user has not chosen a default agent.
|
||||
export const TUI_AGENT_AUTO_PICK_ORDER = [
|
||||
'claude',
|
||||
'claude-agent-teams',
|
||||
'openclaude',
|
||||
'codex',
|
||||
'grok',
|
||||
@@ -36,6 +37,10 @@ export const TUI_AGENT_AUTO_PICK_ORDER = [
|
||||
'openclaw'
|
||||
] as const satisfies readonly TuiAgent[]
|
||||
|
||||
export const DEFAULT_DISABLED_TUI_AGENTS = [
|
||||
'claude-agent-teams'
|
||||
] as const satisfies readonly TuiAgent[]
|
||||
|
||||
export function pickTuiAgent(
|
||||
preferred: TuiAgent | 'blank' | null | undefined,
|
||||
detected: Iterable<TuiAgent>,
|
||||
|
||||
@@ -25,6 +25,7 @@ import type {
|
||||
} from './source-control-ai-types'
|
||||
import type { AgentKind, LaunchSource, RequestKind } from './telemetry-events'
|
||||
import type { SleepingAgentSessionRecord } from './agent-session-resume'
|
||||
import type { ClaudeAgentTeamsMode } from './claude-agent-teams-tmux-compat'
|
||||
|
||||
// Re-exported for backward compat with renderer call sites that import
|
||||
// `WorkspaceCreateTelemetrySource` from '../../../shared/types'.
|
||||
@@ -1842,6 +1843,7 @@ export type ClaudeManagedAccountRuntimeSelection = {
|
||||
* flow and for the default-agent setting. Extend this union as new agents are added. */
|
||||
export type TuiAgent =
|
||||
| 'claude' // Claude Code
|
||||
| 'claude-agent-teams' // Claude Code Agent Teams via Orca native panes
|
||||
| 'openclaude' // OpenClaude
|
||||
| 'codex' // OpenAI Codex
|
||||
| 'autohand' // Autohand Code CLI
|
||||
@@ -2069,6 +2071,9 @@ export type GlobalSettings = {
|
||||
* — can silently rewrite the user's clipboard). Opt-in preserves the
|
||||
* conservative default while making the capability one toggle away. */
|
||||
terminalAllowOsc52Clipboard: boolean
|
||||
/** Experimental Claude Code Agent Teams integration. Native panes use a
|
||||
* tmux-compatible shim so teammate output stays on Orca's normal PTY path. */
|
||||
claudeAgentTeamsMode?: ClaudeAgentTeamsMode
|
||||
/** Where the repo setup script runs on workspace create. Defaults to a
|
||||
* background "Setup" tab so the user's main terminal stays immediately
|
||||
* usable without the setup output crowding the initial pane. */
|
||||
@@ -2169,6 +2174,9 @@ export type GlobalSettings = {
|
||||
/** Agents hidden from future picker and automatic launch choices. Detection
|
||||
* remains a raw PATH capability snapshot. */
|
||||
disabledTuiAgents: TuiAgent[]
|
||||
/** One-shot guard so the experimental Claude Agent Teams launch mode starts
|
||||
* hidden for existing profiles without overriding later user opt-ins. */
|
||||
claudeAgentTeamsDefaultDisabledMigrated?: boolean
|
||||
/** Why: worktree deletion is destructive (git worktree remove + rm -rf of the
|
||||
* working directory), so Orca shows a confirmation dialog by default. Users
|
||||
* who delete frequently can opt into skipping the dialog via a "Don't ask
|
||||
|
||||
Reference in New Issue
Block a user