// Single id generator for queue items, terminal runs, and command templates.
// Replaces three near-identical `newId()` copies that had divergent fallback
// prefixes and could collide within a millisecond (M7 / L33 / L70).
//
// `crypto.randomUUID` is the real path in Electron/Node; the counter-suffixed
// fallback is effectively unreachable but kept so the function is total in any
// host, and the monotonic counter makes two ids minted in the same millisecond
// distinct (the old `Date.now()`-only fallbacks could collide).
let counter = 0

export function newId(prefix = 'id'): string {
  if (typeof crypto !== 'undefined' && crypto.randomUUID) return crypto.randomUUID()
  return `${prefix}-${Date.now()}-${++counter}`
}
