Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.8 KB
Raw Blame
import type { EventProps } from './telemetry-events'
import type { SetupScriptImportCandidate } from './setup-script-imports'

type SetupScriptPromptTelemetry = Omit<EventProps<'setup_script_prompt_shown'>, 'nth_repo_added'>
type SetupScriptPromptActionTelemetry = Omit<
  EventProps<'setup_script_prompt_action'>,
  'nth_repo_added'
>

export type SetupScriptPromptAction = SetupScriptPromptActionTelemetry['action']

export function buildSetupScriptPromptTelemetry({
  candidate,
  hasSharedHooks
}: {
  candidate: SetupScriptImportCandidate | null
  hasSharedHooks: boolean
}): SetupScriptPromptTelemetry {
  const base = {
    // Keep historical wire labels although package-manager suggestions now display as detected setup.
    mode: candidate ? 'import_available' : 'configure_needed',
    file_count_bucket: bucketSetupScriptCount(candidate?.files.length ?? 0),
    unsupported_field_count_bucket: bucketSetupScriptCount(
      candidate?.unsupportedFields?.length ?? 0
    ),
    has_shared_hooks: hasSharedHooks
  } satisfies SetupScriptPromptTelemetry

  return candidate ? { ...base, provider: candidate.provider } : base
}

export function buildSetupScriptPromptActionTelemetry({
  action,
  candidate,
  hasSharedHooks,
  editedBeforeSave
}: {
  action: SetupScriptPromptAction
  candidate: SetupScriptImportCandidate | null
  hasSharedHooks: boolean
  editedBeforeSave?: boolean
}): SetupScriptPromptActionTelemetry {
  return {
    ...buildSetupScriptPromptTelemetry({ candidate, hasSharedHooks }),
    action,
    ...(editedBeforeSave !== undefined ? { edited_before_save: editedBeforeSave } : {})
  }
}

function bucketSetupScriptCount(count: number): SetupScriptPromptTelemetry['file_count_bucket'] {
  if (count <= 0) {
    return '0'
  }
  if (count === 1) {
    return '1'
  }
  if (count <= 3) {
    return '2-3'
  }
  return '4+'
}