mirror of
https://github.com/stablyai/orca.git
synced 2026-09-27 00:02:37 +00:00
* feat(linear): add project support to agent CLI * fix(linear): resolve project names across search pages * fix(linear): harden agent project support * fix(linear): address project review feedback --------- Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
215 lines
7.0 KiB
TypeScript
215 lines
7.0 KiB
TypeScript
import type {
|
|
LinearAttachResult,
|
|
LinearCommentAddResult,
|
|
LinearCreateResult,
|
|
LinearIssueListResult,
|
|
LinearIssueContextResult,
|
|
LinearIssueTaskUpdateResult,
|
|
LinearProjectListResult,
|
|
LinearSearchIssueSummary,
|
|
LinearSearchResult,
|
|
LinearTeamLabelsResult,
|
|
LinearTeamListResult,
|
|
LinearTeamMembersResult,
|
|
LinearTeamStatesResult,
|
|
LinearStatusSetResult
|
|
} from '../shared/linear-agent-access'
|
|
import {
|
|
formatLinearProjectListRows,
|
|
linearProjectListWarningLines
|
|
} from '../shared/linear-project-list-format'
|
|
|
|
export function formatLinearIssue(result: LinearIssueContextResult): string {
|
|
const issue = result.issue
|
|
const lines = [
|
|
`${issue.identifier} ${issue.title}`,
|
|
`URL: ${issue.url}`,
|
|
`State: ${issue.state?.name ?? 'unknown'}`,
|
|
`Assignee: ${issue.assignee?.displayName ?? 'unassigned'}`,
|
|
`Project: ${issue.project?.name ?? 'none'}`
|
|
]
|
|
lines.push(`Priority: ${formatPriority(issue.priority)}`)
|
|
lines.push(`Estimate: ${issue.estimate ?? 'none'}`)
|
|
if (issue.labels.length > 0) {
|
|
lines.push(
|
|
`Labels: ${issue.labels
|
|
.map((label) => label.name)
|
|
.filter(Boolean)
|
|
.join(', ')}`
|
|
)
|
|
}
|
|
if (issue.dueDate) {
|
|
lines.push(`Due: ${issue.dueDate}`)
|
|
}
|
|
const sections = result.meta.sections
|
|
if (sections.comments) {
|
|
lines.push(`Comments: ${sections.comments.returned}`)
|
|
}
|
|
if (sections.children) {
|
|
lines.push(`Children: ${sections.children.returned}`)
|
|
}
|
|
if (sections.attachments) {
|
|
lines.push(`Attachments: ${sections.attachments.returned}`)
|
|
}
|
|
if (sections.relations) {
|
|
lines.push(`Relations: ${sections.relations.returned}`)
|
|
}
|
|
return lines.join('\n')
|
|
}
|
|
|
|
export function formatLinearSearch(result: LinearSearchResult): string {
|
|
if (result.issues.length === 0) {
|
|
return 'No Linear issues found.'
|
|
}
|
|
return result.issues.map(formatSearchRow).join('\n')
|
|
}
|
|
|
|
export function formatLinearTeamList(result: LinearTeamListResult): string {
|
|
if (result.teams.length === 0) {
|
|
return 'No Linear teams found.'
|
|
}
|
|
return result.teams
|
|
.map((team) => {
|
|
const workspace = team.workspace ? ` ${team.workspace.name}` : ''
|
|
return `${team.key.padEnd(10)} ${team.name}${workspace}`
|
|
})
|
|
.join('\n')
|
|
}
|
|
|
|
export function formatLinearTeamMembers(result: LinearTeamMembersResult): string {
|
|
if (result.members.length === 0) {
|
|
return `No Linear members found for ${result.team.key}.`
|
|
}
|
|
return result.members
|
|
.map((member) => `${(member.displayName ?? 'unknown').padEnd(24)} ${member.id ?? ''}`)
|
|
.join('\n')
|
|
}
|
|
|
|
export function formatLinearTeamStates(result: LinearTeamStatesResult): string {
|
|
if (result.states.length === 0) {
|
|
return `No Linear workflow states found for ${result.team.key}.`
|
|
}
|
|
return result.states
|
|
.map((state) => `${state.name.padEnd(24)} ${(state.type ?? '').padEnd(12)} ${state.id}`)
|
|
.join('\n')
|
|
}
|
|
|
|
export function formatLinearTeamLabels(result: LinearTeamLabelsResult): string {
|
|
if (result.labels.length === 0) {
|
|
return `No Linear labels found for ${result.team.key}.`
|
|
}
|
|
return result.labels.map((label) => `${label.name.padEnd(24)} ${label.id}`).join('\n')
|
|
}
|
|
|
|
export function formatLinearIssueList(result: LinearIssueListResult): string {
|
|
if (result.issues.length === 0) {
|
|
return 'No Linear issues found.'
|
|
}
|
|
return result.issues.map(formatSearchRow).join('\n')
|
|
}
|
|
|
|
export function formatLinearProjectList(result: LinearProjectListResult): string {
|
|
return formatLinearProjectListRows(result)
|
|
}
|
|
|
|
export function formatLinearStatusSet(result: LinearStatusSetResult): string {
|
|
const suffix = result.meta.alreadyInState ? ' (already set)' : ''
|
|
return `Set ${result.issue.identifier} to ${result.state.name}${suffix}.`
|
|
}
|
|
|
|
export function formatLinearCommentAdd(result: LinearCommentAddResult): string {
|
|
const suffix = result.meta.deduplicated ? ' (already posted)' : ''
|
|
return `Added comment ${result.comment.id} to ${result.issue.identifier}${suffix}.`
|
|
}
|
|
|
|
export function formatLinearAttach(result: LinearAttachResult): string {
|
|
const suffix = result.meta.deduplicated ? ' (already attached)' : ''
|
|
return `Attached ${result.attachment.title} to ${result.issue.identifier}${suffix}.`
|
|
}
|
|
|
|
export function formatLinearCreate(result: LinearCreateResult): 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 formatLinearTaskUpdate(result: LinearIssueTaskUpdateResult): string {
|
|
const suffix = result.meta.alreadySet ? ' (already set)' : ''
|
|
return `Updated ${result.issue.identifier} ${taskOperationLabel(result.operation)}${suffix}.`
|
|
}
|
|
|
|
export function printLinearIssueWarnings(result: LinearIssueContextResult): void {
|
|
for (const error of result.meta.includeErrors) {
|
|
console.error(`warning: ${error.include} unavailable: ${error.message}`)
|
|
}
|
|
for (const [name, meta] of Object.entries(result.meta.sections)) {
|
|
if (meta?.capReached) {
|
|
console.error(`warning: ${name} capped at ${meta.returned}/${meta.cap}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
export function printLinearSearchWarnings(result: LinearSearchResult): void {
|
|
if (result.meta.limitReached) {
|
|
console.error(`warning: showing first ${result.meta.returned} Linear issues`)
|
|
}
|
|
for (const error of result.meta.workspaceErrors ?? []) {
|
|
console.error(
|
|
`warning: ${error.workspace.name} unavailable for Linear search: ${error.message}`
|
|
)
|
|
}
|
|
}
|
|
|
|
export function printLinearListWarnings(
|
|
result: LinearSearchResult | LinearIssueListResult | LinearTeamListResult
|
|
): void {
|
|
const meta = result.meta
|
|
if ('hasMore' in meta && meta.hasMore) {
|
|
console.error(`warning: showing first ${meta.returned} Linear issues`)
|
|
}
|
|
if ('limitReached' in meta && meta.limitReached) {
|
|
console.error(`warning: showing first ${meta.returned} Linear issues`)
|
|
}
|
|
for (const error of meta.workspaceErrors ?? []) {
|
|
console.error(`warning: ${error.workspace.name} unavailable for Linear: ${error.message}`)
|
|
}
|
|
}
|
|
|
|
export function printLinearProjectListWarnings(result: LinearProjectListResult): void {
|
|
for (const warning of linearProjectListWarningLines(result)) {
|
|
console.error(warning)
|
|
}
|
|
}
|
|
|
|
function formatSearchRow(issue: LinearSearchIssueSummary): string {
|
|
const state = issue.state?.name ?? 'unknown'
|
|
const assignee = issue.assignee?.displayName ?? 'unassigned'
|
|
return `${issue.identifier.padEnd(10)} ${state.padEnd(14)} ${assignee.padEnd(18)} ${issue.title}`
|
|
}
|
|
|
|
function formatPriority(priority: number | null | undefined): string {
|
|
if (priority == null || priority === 0) {
|
|
return 'none'
|
|
}
|
|
switch (priority) {
|
|
case 1:
|
|
return 'urgent'
|
|
case 2:
|
|
return 'high'
|
|
case 3:
|
|
return 'medium'
|
|
case 4:
|
|
return 'low'
|
|
default:
|
|
return 'none'
|
|
}
|
|
}
|
|
|
|
function taskOperationLabel(operation: LinearIssueTaskUpdateResult['operation']): string {
|
|
if (operation === 'dueDate') {
|
|
return 'due date'
|
|
}
|
|
return operation
|
|
}
|