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:
Brennan Benson
2026-07-21 13:25:22 -07:00
committed by GitHub
parent 87af1c8673
commit a10a2ba53c
33 changed files with 1094 additions and 61 deletions
File diff suppressed because one or more lines are too long
+18
View File
@@ -0,0 +1,18 @@
import type {
LinearSaveIssueRequest,
LinearSaveIssueResult
} from '../../shared/linear-agent-access'
import type { CommandHandler } from '../dispatch'
import { printResult } from '../format'
import { formatLinearSaveIssue } from '../linear-format'
import { buildSaveIssueRequest } from '../linear-save-issue-request'
const LINEAR_WRITE_TIMEOUT_MS = 75_000
export const runLinearSaveIssue: CommandHandler = async ({ flags, client, cwd, json }) => {
const request: LinearSaveIssueRequest = await buildSaveIssueRequest(flags, cwd, client.isRemote)
const response = await client.call<LinearSaveIssueResult>('linear.saveIssue', request, {
timeoutMs: LINEAR_WRITE_TIMEOUT_MS
})
printResult(response, json, formatLinearSaveIssue)
}
+40
View File
@@ -564,6 +564,46 @@ describe('orca linear CLI handlers', () => {
)
})
it('maps MCP-style save-issue updates and explicit clears', async () => {
queueFixtures(callMock, okFixture('req_save', createResult()))
await main(
[
'linear',
'save-issue',
'ENG-123',
'--title',
'Updated title',
'--assignee',
'null',
'--estimate',
'null',
'--due-date',
'null',
'--project',
'null',
'--label',
'Bug',
'--json'
],
'/tmp/repo'
)
expect(callMock).toHaveBeenCalledWith(
'linear.saveIssue',
expect.objectContaining({
input: 'ENG-123',
title: 'Updated title',
assignee: null,
estimate: null,
dueDate: null,
project: null,
labels: ['Bug']
}),
{ timeoutMs: 75_000 }
)
})
it('rejects duplicate body inputs before dispatch', async () => {
await main(
['linear', 'create', '--title', 'Bug', '--body', 'one', '--body-file', 'body.md'],
+2
View File
@@ -66,11 +66,13 @@ import {
} from '../linear-format'
import { runLinearListIssues } from './linear-list-issues'
import { linearRelationWriteHandler } from './linear-relation-write'
import { runLinearSaveIssue } from './linear-save-issue'
const ISSUE_CONTEXT_TIMEOUT_MS = 120_000
const LINEAR_WRITE_TIMEOUT_MS = 75_000
export const LINEAR_HANDLERS: Record<string, CommandHandler> = {
'linear save-issue': runLinearSaveIssue,
'linear list-issues': runLinearListIssues,
'linear relation add': linearRelationWriteHandler('add'),
'linear relation remove': linearRelationWriteHandler('remove'),
+9 -1
View File
@@ -7,6 +7,7 @@ import type {
LinearIssueContextResult,
LinearIssueTaskUpdateResult,
LinearIssueRelationWriteResult,
LinearSaveIssueResult,
LinearProjectListResult,
LinearSearchIssueSummary,
LinearSearchResult,
@@ -157,13 +158,20 @@ export function formatLinearAttach(result: LinearAttachResult): string {
return `Attached ${result.attachment.title} to ${result.issue.identifier}${suffix}.`
}
export function formatLinearCreate(result: LinearCreateResult): string {
export 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)' : ''
return `Created ${result.issue.identifier}${parent}${project}: ${result.issue.title}${suffix}.`
}
export function formatLinearSaveIssue(result: LinearSaveIssueResult): string {
if (result.meta.created) {
return formatLinearCreate(result)
}
return `Saved ${result.issue.identifier}: ${result.issue.title}.`
}
export function formatLinearTaskUpdate(result: LinearIssueTaskUpdateResult): string {
const suffix = result.meta.alreadySet ? ' (already set)' : ''
return `Updated ${result.issue.identifier} ${taskOperationLabel(result.operation)}${suffix}.`
+63
View File
@@ -0,0 +1,63 @@
import type { LinearSaveIssueRequest } from '../shared/linear-agent-access'
import {
getOptionalNullableNumberFlag,
getOptionalStringFlag,
getRepeatedStringFlag
} from './flags'
import {
buildLinearCurrentContext,
getDueDateFlag,
getOptionalWriteId,
getPriorityFlag,
readLinearBody,
rejectAllWorkspaceForWrite
} from './linear-request-builders'
import { RuntimeClientError } from './runtime-client'
export async function buildSaveIssueRequest(
flags: Map<string, string | boolean>,
cwd: string,
remote: boolean
): Promise<LinearSaveIssueRequest> {
rejectAllWorkspaceForWrite(flags)
const input = getOptionalStringFlag(flags, 'id')
const current = flags.get('current') === true
if (input && current) {
throw new RuntimeClientError('invalid_argument', 'Pass either <id> or --current, not both')
}
const body = await readLinearBody(flags, cwd, { required: false })
const description = getOptionalStringFlag(flags, 'description')
if (body !== undefined && description !== undefined) {
throw new RuntimeClientError('invalid_argument', 'Use either --description or --body, not both')
}
return {
input,
current,
workspaceId: getOptionalStringFlag(flags, 'workspace'),
context: buildLinearCurrentContext(cwd, remote),
team: getOptionalStringFlag(flags, 'team'),
title: getOptionalStringFlag(flags, 'title'),
description: description ?? body,
state: getOptionalStringFlag(flags, 'state'),
assignee: getNullableStringFlag(flags, 'assignee'),
priority: flags.has('priority') ? getPriorityFlag(flags, 'priority') : undefined,
estimate: getOptionalNullableNumberFlag(flags, 'estimate'),
dueDate: flags.has('due-date') ? getNullableDueDateFlag(flags, 'due-date') : undefined,
labels: flags.has('label') ? getRepeatedStringFlag(flags, 'label') : undefined,
project: getNullableStringFlag(flags, 'project'),
parentId: getNullableStringFlag(flags, 'parent-id'),
writeId: getOptionalWriteId(flags)
}
}
function getNullableStringFlag(
flags: Map<string, string | boolean>,
name: string
): string | null | undefined {
const value = getOptionalStringFlag(flags, name)
return value === 'null' ? null : value
}
function getNullableDueDateFlag(flags: Map<string, string | boolean>, name: string): string | null {
return getOptionalStringFlag(flags, name) === 'null' ? null : getDueDateFlag(flags, name)
}
+37
View File
@@ -2,6 +2,43 @@ import type { CommandSpec } from '../args'
import { GLOBAL_FLAGS } from '../args'
export const LINEAR_COMMAND_SPECS: CommandSpec[] = [
{
path: ['linear', 'save-issue'],
summary: 'Create or update a Linear issue',
usage:
'orca linear save-issue [<id>] [--current] [--team <key|id>] [--title <title>] [--description <text> | --body-file <path|->] [--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]',
allowedFlags: [
...GLOBAL_FLAGS,
'current',
'team',
'title',
'description',
'body',
'body-file',
'state',
'assignee',
'priority',
'estimate',
'due-date',
'label',
'project',
'parent-id',
'write-id',
'workspace',
'id'
],
positionalArgs: ['id'],
examples: [
'orca linear save-issue --team ENG --title "Fix auth" --priority high --json',
'orca linear save-issue ENG-123 --title "Fix OAuth callback" --assignee me --json',
'orca linear save-issue --current --project null --due-date null --json'
],
notes: [
'Without <id> or --current, creates an issue and requires --team and --title.',
'Labels replace the complete label set, matching Linear MCP save_issue semantics.',
'Use the literal null to clear assignee, estimate, due date, project, or parent.'
]
},
{
path: ['linear', 'list-issues'],
summary: 'List Linear issues with MCP-compatible filters',