feat(linear): add MCP-style save issue (#9670)
* feat(linear): add MCP-style save issue * fix(linear): harden save issue parity * fix(linear): close save issue contract gaps * docs(linear): bundle project discovery with save issue
This commit is contained in:
@@ -14,7 +14,8 @@ import type {
|
||||
LinearStatusSetResult,
|
||||
LinearCommentAddResult,
|
||||
LinearAttachResult,
|
||||
LinearCreateResult
|
||||
LinearCreateResult,
|
||||
LinearSaveIssueResult
|
||||
} from '../../shared/linear-agent-access'
|
||||
import {
|
||||
formatLinearProjectListRows,
|
||||
@@ -24,6 +25,7 @@ import {
|
||||
isLinearAttachResult,
|
||||
isLinearCommentAddResult,
|
||||
isLinearCreateResult,
|
||||
isLinearSaveIssueResult,
|
||||
isLinearIssueContextResult,
|
||||
isLinearIssueListResult,
|
||||
isLinearMcpIssueListResult,
|
||||
@@ -93,6 +95,9 @@ export function formatRemoteLinearCli(result: unknown): { stdout: string; stderr
|
||||
if (isLinearAttachResult(result)) {
|
||||
return { stdout: `${formatLinearAttach(result)}\n`, stderr: '' }
|
||||
}
|
||||
if (isLinearSaveIssueResult(result)) {
|
||||
return { stdout: `${formatLinearSaveIssue(result)}\n`, stderr: '' }
|
||||
}
|
||||
if (isLinearCreateResult(result)) {
|
||||
return { stdout: `${formatLinearCreate(result)}\n`, stderr: '' }
|
||||
}
|
||||
@@ -133,6 +138,12 @@ function formatLinearIssue(result: LinearIssueContextResult): string {
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
function formatLinearSaveIssue(result: LinearSaveIssueResult): string {
|
||||
return result.meta.created
|
||||
? formatLinearCreate(result)
|
||||
: `Saved ${result.issue.identifier}: ${result.issue.title}.`
|
||||
}
|
||||
|
||||
function formatLinearIssueRows(issues: LinearSearchIssueSummary[]): string {
|
||||
if (issues.length === 0) {
|
||||
return 'No Linear issues found.'
|
||||
@@ -231,7 +242,7 @@ function formatLinearAttach(result: LinearAttachResult): string {
|
||||
return `Attached ${result.attachment.title} to ${result.issue.identifier}${suffix}.`
|
||||
}
|
||||
|
||||
function formatLinearCreate(result: LinearCreateResult): string {
|
||||
function formatLinearCreate(result: LinearCreateResult | LinearSaveIssueResult): string {
|
||||
const parent = result.issue.parent ? ` under ${result.issue.parent.identifier}` : ''
|
||||
const project = result.issue.project?.name ? ` in ${result.issue.project.name}` : ''
|
||||
const suffix = result.meta.deduplicated ? ' (already created)' : ''
|
||||
|
||||
@@ -44,6 +44,7 @@ const LINEAR_HELP = `orca linear
|
||||
Usage: orca linear <command> [options]
|
||||
|
||||
Commands:
|
||||
save-issue Create or update a Linear issue
|
||||
list-issues List Linear issues with MCP-compatible filters
|
||||
relation add Add a Linear issue relation
|
||||
relation remove Remove a Linear issue relation
|
||||
|
||||
@@ -2,6 +2,7 @@ import type {
|
||||
LinearAttachResult,
|
||||
LinearCommentAddResult,
|
||||
LinearCreateResult,
|
||||
LinearSaveIssueResult,
|
||||
LinearIssueContextResult,
|
||||
LinearIssueListResult,
|
||||
LinearMcpIssueListResult,
|
||||
@@ -162,6 +163,17 @@ export function isLinearCreateResult(result: unknown): result is LinearCreateRes
|
||||
)
|
||||
}
|
||||
|
||||
export function isLinearSaveIssueResult(result: unknown): result is LinearSaveIssueResult {
|
||||
return (
|
||||
isRecord(result) &&
|
||||
isRecord(result.issue) &&
|
||||
isRecord(result.meta) &&
|
||||
typeof result.issue.identifier === 'string' &&
|
||||
typeof result.issue.title === 'string' &&
|
||||
typeof result.meta.created === 'boolean'
|
||||
)
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return Boolean(value) && typeof value === 'object'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { OrcaRuntimeService } from '../runtime/orca-runtime'
|
||||
import { runRemoteOrcaCli } from './ssh-remote-orca-cli'
|
||||
|
||||
function createRuntime() {
|
||||
const linearSaveIssue = vi.fn(async (request: unknown) => ({
|
||||
request,
|
||||
issue: {
|
||||
id: 'issue-1',
|
||||
identifier: 'ENG-123',
|
||||
title: 'Updated title',
|
||||
url: 'https://linear.app/acme/issue/ENG-123',
|
||||
team: { id: 'team-1', key: 'ENG', name: 'Engineering' },
|
||||
state: { id: 'state-1', name: 'Todo' },
|
||||
parent: null
|
||||
},
|
||||
meta: { workspaceId: 'workspace-1', created: false }
|
||||
}))
|
||||
return {
|
||||
runtime: {
|
||||
getRuntimeId: () => 'runtime-test',
|
||||
linearSaveIssue
|
||||
} as unknown as OrcaRuntimeService,
|
||||
linearSaveIssue
|
||||
}
|
||||
}
|
||||
|
||||
describe('SSH remote Linear save issue', () => {
|
||||
it('forwards update fields, clears, stdin, and SSH context without losing types', async () => {
|
||||
const { runtime, linearSaveIssue } = createRuntime()
|
||||
const result = await runRemoteOrcaCli(runtime, {
|
||||
argv: [
|
||||
'linear',
|
||||
'save-issue',
|
||||
'ENG-123',
|
||||
'--body-file',
|
||||
'-',
|
||||
'--assignee',
|
||||
'null',
|
||||
'--estimate',
|
||||
'null',
|
||||
'--due-date',
|
||||
'null',
|
||||
'--label',
|
||||
'Bug',
|
||||
'--label',
|
||||
'Regression',
|
||||
'--json'
|
||||
],
|
||||
cwd: '/home/alice/remote-repo',
|
||||
env: {
|
||||
ORCA_TERMINAL_HANDLE: 'term_ssh',
|
||||
ORCA_WORKTREE_ID: 'repo::remote'
|
||||
},
|
||||
stdin: 'Updated description'
|
||||
})
|
||||
|
||||
expect(result.exitCode).toBe(0)
|
||||
expect(linearSaveIssue).toHaveBeenCalledWith({
|
||||
input: 'ENG-123',
|
||||
current: false,
|
||||
workspaceId: undefined,
|
||||
context: {
|
||||
remote: true,
|
||||
terminalHandle: 'term_ssh',
|
||||
worktreeId: 'repo::remote'
|
||||
},
|
||||
team: undefined,
|
||||
title: undefined,
|
||||
description: 'Updated description',
|
||||
state: undefined,
|
||||
assignee: null,
|
||||
priority: undefined,
|
||||
estimate: null,
|
||||
dueDate: null,
|
||||
labels: ['Bug', 'Regression'],
|
||||
project: undefined,
|
||||
parentId: undefined,
|
||||
writeId: undefined
|
||||
})
|
||||
})
|
||||
|
||||
it('forwards the team and title required for create mode', async () => {
|
||||
const { runtime, linearSaveIssue } = createRuntime()
|
||||
const result = await runRemoteOrcaCli(runtime, {
|
||||
argv: ['linear', 'save-issue', '--team', 'ENG', '--title', 'New issue', '--json'],
|
||||
cwd: '/home/alice/remote-repo',
|
||||
env: { ORCA_TERMINAL_HANDLE: 'term_ssh' }
|
||||
})
|
||||
|
||||
expect(result.exitCode).toBe(0)
|
||||
expect(linearSaveIssue).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ input: undefined, current: false, team: 'ENG', title: 'New issue' })
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects remote body paths instead of reading from the wrong filesystem', async () => {
|
||||
const { runtime, linearSaveIssue } = createRuntime()
|
||||
const result = await runRemoteOrcaCli(runtime, {
|
||||
argv: ['linear', 'save-issue', 'ENG-123', '--body-file', 'body.md', '--json'],
|
||||
cwd: '/home/alice/remote-repo',
|
||||
env: { ORCA_TERMINAL_HANDLE: 'term_ssh' }
|
||||
})
|
||||
|
||||
expect(result.exitCode).toBe(1)
|
||||
expect(linearSaveIssue).not.toHaveBeenCalled()
|
||||
expect(JSON.parse(result.stdout)).toMatchObject({
|
||||
ok: false,
|
||||
error: { code: 'invalid_argument' }
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,128 @@
|
||||
import type { RpcResponse } from '../runtime/rpc/core'
|
||||
import type { RpcDispatcher } from '../runtime/rpc/dispatcher'
|
||||
import {
|
||||
RemoteLinearWriteArgumentError,
|
||||
buildRemoteContext,
|
||||
call,
|
||||
dueDateFlag,
|
||||
nonNegativeIntegerFlag,
|
||||
optionalString,
|
||||
optionalWriteId,
|
||||
priorityFlag,
|
||||
readRemoteBody,
|
||||
repeatedString,
|
||||
rejectAllWorkspaceForWrite,
|
||||
validateLinearRemoteArgs
|
||||
} from './ssh-remote-linear-write-support'
|
||||
|
||||
type ParsedRemoteCli = {
|
||||
commandPath: string[]
|
||||
flags: Map<string, string | boolean>
|
||||
}
|
||||
|
||||
const LINEAR_SAVE_ISSUE_FLAGS = new Set([
|
||||
'help',
|
||||
'json',
|
||||
'pairing-code',
|
||||
'environment',
|
||||
'workspace',
|
||||
'current',
|
||||
'id',
|
||||
'team',
|
||||
'title',
|
||||
'description',
|
||||
'body',
|
||||
'body-file',
|
||||
'state',
|
||||
'assignee',
|
||||
'priority',
|
||||
'estimate',
|
||||
'due-date',
|
||||
'label',
|
||||
'project',
|
||||
'parent-id',
|
||||
'write-id'
|
||||
])
|
||||
|
||||
export async function dispatchRemoteLinearSaveIssue(
|
||||
dispatcher: RpcDispatcher,
|
||||
parsed: ParsedRemoteCli,
|
||||
env: Record<string, string>,
|
||||
stdin?: string
|
||||
): Promise<RpcResponse> {
|
||||
validateLinearRemoteArgs(parsed, LINEAR_SAVE_ISSUE_FLAGS, ['linear', 'save-issue'], 1, 'id')
|
||||
rejectAllWorkspaceForWrite(parsed.flags)
|
||||
const body = readRemoteBody(parsed.flags, false, stdin)
|
||||
const description = optionalString(parsed.flags, 'description')
|
||||
if (body !== undefined && description !== undefined) {
|
||||
throw new RemoteLinearWriteArgumentError(
|
||||
'invalid_argument',
|
||||
'Use either --description or --body, not both'
|
||||
)
|
||||
}
|
||||
return await call(dispatcher, 'linear.saveIssue', {
|
||||
...buildOptionalRemoteTargetRequest(parsed, env),
|
||||
team: optionalString(parsed.flags, 'team'),
|
||||
title: optionalString(parsed.flags, 'title'),
|
||||
description: description ?? body,
|
||||
state: optionalString(parsed.flags, 'state'),
|
||||
assignee: nullableString(parsed.flags, 'assignee'),
|
||||
priority: parsed.flags.has('priority') ? priorityFlag(parsed.flags, 'priority') : undefined,
|
||||
estimate: nullableNonNegativeInteger(parsed.flags, 'estimate'),
|
||||
dueDate: nullableDueDate(parsed.flags, 'due-date'),
|
||||
labels: parsed.flags.has('label') ? repeatedString(parsed.flags, 'label') : undefined,
|
||||
project: nullableString(parsed.flags, 'project'),
|
||||
parentId: nullableString(parsed.flags, 'parent-id'),
|
||||
writeId: optionalWriteId(parsed.flags)
|
||||
})
|
||||
}
|
||||
|
||||
function buildOptionalRemoteTargetRequest(
|
||||
parsed: ParsedRemoteCli,
|
||||
env: Record<string, string>
|
||||
): Record<string, unknown> {
|
||||
const input = optionalString(parsed.flags, 'id') ?? parsed.commandPath.slice(2).join(' ').trim()
|
||||
const current = parsed.flags.get('current') === true
|
||||
if (input && current) {
|
||||
throw new RemoteLinearWriteArgumentError(
|
||||
'invalid_argument',
|
||||
'Pass either <id> or --current, not both'
|
||||
)
|
||||
}
|
||||
return {
|
||||
input: input || undefined,
|
||||
current,
|
||||
workspaceId: optionalString(parsed.flags, 'workspace'),
|
||||
context: buildRemoteContext(env)
|
||||
}
|
||||
}
|
||||
|
||||
function nullableString(
|
||||
flags: Map<string, string | boolean>,
|
||||
name: string
|
||||
): string | null | undefined {
|
||||
const value = optionalString(flags, name)
|
||||
return value === 'null' ? null : value
|
||||
}
|
||||
|
||||
function nullableNonNegativeInteger(
|
||||
flags: Map<string, string | boolean>,
|
||||
name: string
|
||||
): number | null | undefined {
|
||||
const value = optionalString(flags, name)
|
||||
if (value === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return value === 'null' ? null : nonNegativeIntegerFlag(flags, name)
|
||||
}
|
||||
|
||||
function nullableDueDate(
|
||||
flags: Map<string, string | boolean>,
|
||||
name: string
|
||||
): string | null | undefined {
|
||||
const value = optionalString(flags, name)
|
||||
if (value === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return value === 'null' ? null : dueDateFlag(flags, name)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type { RpcResponse } from '../runtime/rpc/core'
|
||||
import type { RpcDispatcher } from '../runtime/rpc/dispatcher'
|
||||
import { getRemoteLinearWriteHelp } from './ssh-remote-linear-write-help'
|
||||
import { dispatchRemoteLinearRelationWrite } from './ssh-remote-linear-relation-write'
|
||||
import { dispatchRemoteLinearSaveIssue } from './ssh-remote-linear-save-issue'
|
||||
import {
|
||||
RemoteLinearWriteArgumentError,
|
||||
buildRemoteContext,
|
||||
@@ -60,13 +61,15 @@ const LINEAR_CREATE_FLAGS = new Set([
|
||||
'parent-current',
|
||||
'write-id'
|
||||
])
|
||||
|
||||
export async function tryDispatchRemoteLinearWriteCli(
|
||||
dispatcher: RpcDispatcher,
|
||||
parsed: ParsedRemoteCli,
|
||||
env: Record<string, string>,
|
||||
stdin?: string
|
||||
): Promise<RpcResponse | null> {
|
||||
if (isRemoteCommand(parsed, 'linear', 'save-issue')) {
|
||||
return await dispatchRemoteLinearSaveIssue(dispatcher, parsed, env, stdin)
|
||||
}
|
||||
if (isRemoteCommand(parsed, 'linear', 'relation', 'add')) {
|
||||
return await dispatchRemoteLinearRelationWrite(dispatcher, parsed, env, 'add')
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ function matchesRemoteCommand(commandPath: string[], ...command: string[]): bool
|
||||
|
||||
export function getRemoteLinearWriteHelp(parsed: ParsedRemoteCli): string | null {
|
||||
const path = parsed.commandPath
|
||||
if (matchesRemoteCommand(path, 'linear', 'save-issue')) {
|
||||
return LINEAR_SAVE_ISSUE_HELP
|
||||
}
|
||||
if (matchesRemoteCommand(path, 'linear', 'relation', 'add')) {
|
||||
return LINEAR_RELATION_ADD_HELP
|
||||
}
|
||||
@@ -69,6 +72,7 @@ export function getRemoteLinearWriteHelp(parsed: ParsedRemoteCli): string | null
|
||||
return null
|
||||
}
|
||||
|
||||
const LINEAR_SAVE_ISSUE_HELP = `orca linear save-issue\n\nUsage: orca linear save-issue [<id>] [--current] [--team <key|id>] [--title <title>] [--description <text> | --body-file -] [--state <state>] [--assignee me|<user>|null] [--priority none|low|medium|high|urgent] [--estimate <number>|null] [--due-date <yyyy-mm-dd>|null] [--label <label>...] [--project <project>|null] [--parent-id <issue>|null] [--write-id <uuid>] [--workspace <id>] [--json]\n\nCreate or update a Linear issue`
|
||||
const LINEAR_RELATION_ADD_HELP = `orca linear relation add\n\nUsage: orca linear relation add [<id>] [--current] --related <issue> --type blocks|blocked-by|related|duplicate-of [--workspace <id>] [--json]\n\nAdd a Linear issue relation`
|
||||
const LINEAR_RELATION_REMOVE_HELP = `orca linear relation remove\n\nUsage: orca linear relation remove [<id>] [--current] --related <issue> --type blocks|blocked-by|related|duplicate-of [--workspace <id>] [--json]\n\nRemove a Linear issue relation`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user