mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 10:37:35 +00:00
Return optional warnings from the owning host when a requested workspace status does not match its configured columns. Preserve the requested write and older-peer behavior; show warnings separately from normal CLI output. Co-authored-by: Kalvin Mizzi <kalvin@mizzi.com>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import type { WorkspaceStatusDefinition } from './worktree/types'
|
|
import {
|
|
getWorkspaceStatus,
|
|
isWorkspaceStatusId,
|
|
normalizeWorkspaceStatuses
|
|
} from './workspace-statuses'
|
|
|
|
export type WorkspaceStatusWarning = {
|
|
code: 'UNKNOWN_WORKSPACE_STATUS'
|
|
message: string
|
|
details: { requestedId: string; effectiveId: string; validIds: string[] }
|
|
}
|
|
|
|
export function getWorkspaceStatusWarning(
|
|
requestedId: string | undefined,
|
|
readStatuses: () => unknown
|
|
): WorkspaceStatusWarning | undefined {
|
|
if (requestedId === undefined) {
|
|
return undefined
|
|
}
|
|
let statuses: WorkspaceStatusDefinition[]
|
|
try {
|
|
statuses = normalizeWorkspaceStatuses(readStatuses())
|
|
} catch {
|
|
// A columns read must not turn a successful metadata write into a failure.
|
|
return undefined
|
|
}
|
|
if (isWorkspaceStatusId(requestedId, statuses)) {
|
|
return undefined
|
|
}
|
|
const effectiveId = getWorkspaceStatus({ workspaceStatus: requestedId }, statuses)
|
|
const label = statuses.find((status) => status.id === effectiveId)?.label ?? effectiveId
|
|
const validIds = statuses.map((status) => status.id)
|
|
return {
|
|
code: 'UNKNOWN_WORKSPACE_STATUS',
|
|
message: `Unknown workspace status ${JSON.stringify(requestedId)}. The board will show this workspace under ${JSON.stringify(label)} (${effectiveId}). Valid status ids: ${validIds.join(', ')}. The requested value was saved.`,
|
|
details: { requestedId, effectiveId, validIds }
|
|
}
|
|
}
|