Add read-only orca linear CLI with trusted launch-prompt pointer (V1) (#5126)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
+4
-12
@@ -57,6 +57,8 @@ import {
|
||||
import { assertPluginSourceUnderByteCap } from './plugin-source-limit'
|
||||
import { resolveOpenCodeSourceConfigDir, resolvePiSourceAgentDir } from './plugin-overlay-env'
|
||||
import { detectPiAgentKindFromCommand } from '../shared/pi-agent-kind'
|
||||
import { pickRemoteCliEnv } from './remote-cli-env'
|
||||
import { remoteCliRequestTimeoutMs } from './remote-cli-timeout'
|
||||
|
||||
const DEFAULT_GRACE_MS = DEFAULT_SSH_RELAY_GRACE_PERIOD_SECONDS * 1000
|
||||
const SOCK_NAME = 'relay.sock'
|
||||
@@ -297,17 +299,6 @@ function runOrcaCliMode(sockPath: string, argv: string[]): void {
|
||||
})
|
||||
}
|
||||
|
||||
function pickRemoteCliEnv(env: NodeJS.ProcessEnv): Record<string, string> {
|
||||
const picked: Record<string, string> = {}
|
||||
for (const key of ['ORCA_TERMINAL_HANDLE', 'ORCA_USER_DATA_PATH', 'PATH', 'Path']) {
|
||||
const value = env[key]
|
||||
if (typeof value === 'string') {
|
||||
picked[key] = value
|
||||
}
|
||||
}
|
||||
return picked
|
||||
}
|
||||
|
||||
// ── Normal mode ──────────────────────────────────────────────────────
|
||||
|
||||
async function main(): Promise<void> {
|
||||
@@ -439,7 +430,8 @@ async function main(): Promise<void> {
|
||||
|
||||
dispatcher.onRequest('orca.cli', async (params, context) => {
|
||||
return await dispatcher.requestAnyClient('orca.cli', params, {
|
||||
excludeClientId: context.clientId
|
||||
excludeClientId: context.clientId,
|
||||
timeoutMs: remoteCliRequestTimeoutMs(params)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { pickRemoteCliEnv } from './remote-cli-env'
|
||||
|
||||
describe('pickRemoteCliEnv', () => {
|
||||
it('forwards SSH Orca terminal and worktree context for remote CLI calls', () => {
|
||||
expect(
|
||||
pickRemoteCliEnv({
|
||||
ORCA_TERMINAL_HANDLE: 'term_ssh',
|
||||
ORCA_WORKTREE_ID: 'repo::remote',
|
||||
ORCA_USER_DATA_PATH: '/tmp/orca',
|
||||
PATH: '/usr/bin',
|
||||
SECRET_TOKEN: 'nope'
|
||||
})
|
||||
).toEqual({
|
||||
ORCA_TERMINAL_HANDLE: 'term_ssh',
|
||||
ORCA_WORKTREE_ID: 'repo::remote',
|
||||
ORCA_USER_DATA_PATH: '/tmp/orca',
|
||||
PATH: '/usr/bin'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
export function pickRemoteCliEnv(env: NodeJS.ProcessEnv): Record<string, string> {
|
||||
const picked: Record<string, string> = {}
|
||||
for (const key of [
|
||||
'ORCA_TERMINAL_HANDLE',
|
||||
'ORCA_WORKTREE_ID',
|
||||
'ORCA_USER_DATA_PATH',
|
||||
'PATH',
|
||||
'Path'
|
||||
]) {
|
||||
const value = env[key]
|
||||
if (typeof value === 'string') {
|
||||
picked[key] = value
|
||||
}
|
||||
}
|
||||
return picked
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { remoteCliRequestTimeoutMs } from './remote-cli-timeout'
|
||||
|
||||
describe('remoteCliRequestTimeoutMs', () => {
|
||||
it('extends SSH remote CLI timeout for Linear issue context reads', () => {
|
||||
expect(
|
||||
remoteCliRequestTimeoutMs({
|
||||
argv: ['linear', 'issue', 'ENG-123', '--json']
|
||||
})
|
||||
).toBe(120_000)
|
||||
})
|
||||
|
||||
it('extends the timeout when global flags appear before the Linear command', () => {
|
||||
expect(
|
||||
remoteCliRequestTimeoutMs({
|
||||
argv: ['--json', 'linear', 'issue', 'ENG-123', '--workspace', 'workspace-1', '--full']
|
||||
})
|
||||
).toBe(120_000)
|
||||
})
|
||||
|
||||
it('extends SSH remote CLI timeout for Linear search', () => {
|
||||
expect(
|
||||
remoteCliRequestTimeoutMs({
|
||||
argv: ['linear', 'search', 'auth', '--limit', '1']
|
||||
})
|
||||
).toBe(120_000)
|
||||
})
|
||||
|
||||
it('extends the timeout when boolean flags appear between Linear and search', () => {
|
||||
expect(
|
||||
remoteCliRequestTimeoutMs({
|
||||
argv: ['linear', '--json', 'search', 'auth', '--limit', '1']
|
||||
})
|
||||
).toBe(120_000)
|
||||
})
|
||||
|
||||
it('extends the timeout when boolean flags appear between Linear and issue', () => {
|
||||
expect(
|
||||
remoteCliRequestTimeoutMs({
|
||||
argv: ['linear', '--json', 'issue', 'ENG-123', '--full']
|
||||
})
|
||||
).toBe(120_000)
|
||||
})
|
||||
|
||||
it('keeps ordinary remote CLI requests on the relay default timeout', () => {
|
||||
expect(remoteCliRequestTimeoutMs({ argv: ['status'] })).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,52 @@
|
||||
const LINEAR_ISSUE_CONTEXT_TIMEOUT_MS = 120_000
|
||||
const REMOTE_TIMEOUT_BOOLEAN_FLAGS = new Set([
|
||||
'all',
|
||||
'attachments',
|
||||
'children',
|
||||
'comments',
|
||||
'current',
|
||||
'full',
|
||||
'help',
|
||||
'inject',
|
||||
'json',
|
||||
'relations',
|
||||
'unread',
|
||||
'wait'
|
||||
])
|
||||
|
||||
export function remoteCliRequestTimeoutMs(params: Record<string, unknown>): number | undefined {
|
||||
return isLinearCliRequest(params) ? LINEAR_ISSUE_CONTEXT_TIMEOUT_MS : undefined
|
||||
}
|
||||
|
||||
function isLinearCliRequest(params: Record<string, unknown>): boolean {
|
||||
const argv = params.argv
|
||||
if (!Array.isArray(argv) || !argv.every((part) => typeof part === 'string')) {
|
||||
return false
|
||||
}
|
||||
const commandPath = parseRemoteCommandPath(argv)
|
||||
return commandPath.some(
|
||||
(part, index) => part === 'linear' && ['issue', 'search'].includes(commandPath[index + 1] ?? '')
|
||||
)
|
||||
}
|
||||
|
||||
function parseRemoteCommandPath(argv: string[]): string[] {
|
||||
const commandPath: string[] = []
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const token = argv[index]
|
||||
if (!token.startsWith('--')) {
|
||||
commandPath.push(token)
|
||||
continue
|
||||
}
|
||||
|
||||
const assignment = token.slice(2)
|
||||
if (assignment.includes('=')) {
|
||||
continue
|
||||
}
|
||||
|
||||
const next = argv[index + 1]
|
||||
if (!REMOTE_TIMEOUT_BOOLEAN_FLAGS.has(assignment) && next && !next.startsWith('--')) {
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
return commandPath
|
||||
}
|
||||
Reference in New Issue
Block a user