Files
orca/src/cli/reference-input.ts
T
Neil 15717a4e53 Add CLI commands to manage and find workspace references (#26807)
* Add CLI commands to manage and find workspace references

* Fix reference review findings: source-context twins, legacy link collapse, closed chats, old-host errors

- Keep same-URL links with different source contexts separate; CLI add/remove no longer drops a twin
- Restore merging a bare legacy link into its single matching URL link (no duplicate PR rows, no resurrection on older-client removal)
- Carry absorbed data through collapse chains; resolve repoId conflicts deterministically
- Identity: ignore www., case-insensitive GitHub/GitLab/Gitea paths (stored URL keeps case), no Jira match on git hosts; find accepts self-hosted issue URLs
- reference find: skip closed native chats, require a session id for linked, include an explicitly named archived workspace, warm-cache fallback for --worktree
- Selector parity: collapse same-host duplicate paths, issue: ignores unlinked rows
- CLI: clear update-host error for hosts without reference.*, local flag checks before host probe, help text fixes

* Fix CI: add reference rm alias for verb policy; expect linkedItems in worktree ps summary

* Simplify reference CLI: share identifier/legacy-match helpers, drop redundant dedupe
2026-10-09 22:22:01 -07:00

57 lines
2.0 KiB
TypeScript

import type { WorkspaceAttachment } from '../shared/worktree/types'
import type { RuntimeStatus } from '../shared/runtime-types'
import { WORKTREE_LINKED_ITEMS_DELTA_RUNTIME_CAPABILITY } from '../shared/workspace-attachment-capabilities'
import {
getWorkspaceReferenceIdentity,
parseWorkspaceReferenceUrl
} from '../shared/workspace-reference-identity'
import type { RuntimeClient } from './runtime-client'
import { RuntimeClientError } from './runtime-client'
import { getRepeatedStringFlag } from './flags'
export function parseReferenceUrls(urls: string[]): WorkspaceAttachment[] {
try {
const references = urls.map((url) => parseWorkspaceReferenceUrl(url))
return [
...new Map(references.map((item) => [getWorkspaceReferenceIdentity(item), item])).values()
]
} catch (error) {
throw new RuntimeClientError(
'invalid_argument',
error instanceof Error ? error.message : 'Pass a full issue or review URL.'
)
}
}
export async function assertReferenceWritesSupported(client: RuntimeClient): Promise<void> {
const status = await client.call<RuntimeStatus>('status.get')
if (!status.result.capabilities?.includes(WORKTREE_LINKED_ITEMS_DELTA_RUNTIME_CAPABILITY)) {
throw new RuntimeClientError(
'incompatible_runtime',
'This Orca host cannot merge reference changes safely. Update Orca on the execution host.'
)
}
}
export function getCreateReferences(
flags: Map<string, string | boolean>
): WorkspaceAttachment[] | undefined {
if (!flags.has('reference')) {
return undefined
}
const legacy = ['issue', 'pr', 'linear-issue', 'gitlab-issue', 'gitlab-mr'].find((name) =>
flags.has(name)
)
if (legacy) {
throw new RuntimeClientError('invalid_argument', `Cannot combine --reference with --${legacy}.`)
}
const urls = getRepeatedStringFlag(flags, 'reference')
if (urls.length === 0) {
throw new RuntimeClientError(
'invalid_argument',
'--reference requires a full issue or review URL.'
)
}
return parseReferenceUrls(urls)
}