import type { ProcessCommandKind, ProcessExecutionMetadata, ProcessExecutionStatus, } from '../../types.js'; /** Conservative command classification: false negatives are safer than claiming an unrun verification. */ export function classifyProcessCommand(command: string): ProcessCommandKind { const normalized = command.trim(); if (/(?:^|[;&|]\s*)(?:bun|npm|pnpm|yarn)\s+(?:run\s+)?test(?:\s|$)|(?:^|[;&|]\s*)cargo\s+test(?:\s|$)/i.test(normalized)) return 'test'; if (/(?:^|[;&|]\s*)(?:bun|npm|pnpm|yarn)\s+(?:run\s+)?typecheck(?:\s|$)|(?:^|[;&|]\s*)(?:npx\s+)?tsc(?:\s|$)/i.test(normalized)) return 'typecheck'; if (/(?:^|[;&|]\s*)(?:bun|npm|pnpm|yarn)\s+(?:run\s+)?build(?:\s|$)|(?:^|[;&|]\s*)cargo\s+build(?:\s|$)/i.test(normalized)) return 'build'; if (/(?:^|[;&|]\s*)(?:bun|npm|pnpm|yarn)\s+(?:run\s+)?check(?:\s|$)|(?:^|[;&|]\s*)cargo\s+check(?:\s|$)/i.test(normalized)) return 'check'; return 'other'; } export function processExecutionMetadata(input: { shell: 'bash' | 'powershell'; mode: 'foreground' | 'background'; command: string; status: ProcessExecutionStatus; taskId?: string; exitCode?: number | null; }): ProcessExecutionMetadata { return { kind: 'process_execution', shell: input.shell, mode: input.mode, commandKind: classifyProcessCommand(input.command), status: input.status, ...(input.taskId ? { taskId: input.taskId } : {}), ...(input.exitCode !== undefined ? { exitCode: input.exitCode } : {}), }; }