feat(telemetry): track agent_hook_install_failed per agent (#1668)
* feat(telemetry): track agent_hook_install_failed per agent Replaces the closure-style installer loop in `src/main/index.ts` with a labelled `runManagedHookInstallers` so each catch can attribute the failure to its agent. Adds the `agent_hook_install_failed` event + `hookInstallAgentSchema` enum (claude/codex/gemini/cursor) and a unit test pinning fail-open semantics, label routing, and the 200-char error_message truncation. Co-authored-by: Orca <help@stably.ai> * fix(telemetry): harden agent-hook installer fail-open - describeError always returns a string (JSON.stringify can return literal undefined for throw undefined / Symbol / function, which would crash the catch handler before track fires) - wrap track() in inner try/catch so a telemetry-side throw can't abort the installer loop - dedupe AGENT_HOOK_TARGETS into one tuple in agent-hook-types so the IPC AgentHookTarget type and hookInstallAgentSchema can't drift - regression tests for object/undefined throws and track-throws Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
// gemini/cursor/hook-service.ts). Lives in `shared/` to keep a single
|
||||
// source of truth for the version string and status contract.
|
||||
|
||||
export type AgentHookTarget = 'claude' | 'codex' | 'gemini' | 'cursor'
|
||||
export const AGENT_HOOK_TARGETS = ['claude', 'codex', 'gemini', 'cursor'] as const
|
||||
export type AgentHookTarget = (typeof AGENT_HOOK_TARGETS)[number]
|
||||
|
||||
export type AgentHookInstallState = 'installed' | 'not_installed' | 'partial' | 'error'
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
import { z } from 'zod'
|
||||
|
||||
import { AGENT_HOOK_TARGETS } from './agent-hook-types'
|
||||
import { ONBOARDING_FINAL_STEP } from './constants'
|
||||
import type { DiscoveryStatusEmitted, GlobalSettings, OnboardingChecklistState } from './types'
|
||||
|
||||
@@ -250,6 +251,27 @@ const workspaceCreateFailedSchema = z
|
||||
})
|
||||
.strict()
|
||||
|
||||
// Managed-hook installer per-agent label. Distinct from `AGENT_KIND_VALUES`:
|
||||
// hook installation only targets these four agents and the labels here match
|
||||
// the `*HookService.install()` call sites in `src/main/index.ts`. `claude`
|
||||
// (not `claude-code`) is intentional — the failure is about Claude Code's
|
||||
// `~/.claude/settings.json`, not the broader product taxonomy. Sourced from
|
||||
// `AGENT_HOOK_TARGETS` so the wire enum and the IPC `AgentHookTarget` type
|
||||
// cannot drift if a fifth hook-install agent is added.
|
||||
export const hookInstallAgentSchema = z.enum(AGENT_HOOK_TARGETS)
|
||||
export type HookInstallAgent = z.infer<typeof hookInstallAgentSchema>
|
||||
|
||||
// Why: install failures are config-file-shape errors (malformed JSON, missing
|
||||
// keys, ACL denials on `~/.claude` etc.) — not user content. The 200-char
|
||||
// cap is the truncation contract; callers must truncate before calling
|
||||
// `track`, and the validator will drop overlength strings via `.max(200)`.
|
||||
const agentHookInstallFailedSchema = z
|
||||
.object({
|
||||
agent: hookInstallAgentSchema,
|
||||
error_message: z.string().max(200)
|
||||
})
|
||||
.strict()
|
||||
|
||||
// ── Onboarding ──────────────────────────────────────────────────────────
|
||||
//
|
||||
// Closed enums only — no raw paths, repo names, clone URLs, or error
|
||||
@@ -461,6 +483,7 @@ export const eventSchemas = {
|
||||
|
||||
agent_started: agentStartedSchema,
|
||||
agent_error: agentErrorSchema,
|
||||
agent_hook_install_failed: agentHookInstallFailedSchema,
|
||||
|
||||
settings_changed: settingsChangedSchema,
|
||||
|
||||
@@ -528,12 +551,11 @@ type _CohortExtendedRoster =
|
||||
type _DerivedCohortExtendedEvents = {
|
||||
[N in EventName]: 'nth_repo_added' extends keyof EventMap[N] ? N : never
|
||||
}[EventName]
|
||||
type _CohortExtendedRosterSync =
|
||||
_CohortExtendedRoster extends _DerivedCohortExtendedEvents
|
||||
? _DerivedCohortExtendedEvents extends _CohortExtendedRoster
|
||||
? true
|
||||
: never
|
||||
type _CohortExtendedRosterSync = _CohortExtendedRoster extends _DerivedCohortExtendedEvents
|
||||
? _DerivedCohortExtendedEvents extends _CohortExtendedRoster
|
||||
? true
|
||||
: never
|
||||
: never
|
||||
const _cohortExtendedRosterSyncCheck: _CohortExtendedRosterSync = true
|
||||
void _cohortExtendedRosterSyncCheck
|
||||
|
||||
@@ -577,12 +599,11 @@ type _OnboardingCohortRoster =
|
||||
type _DerivedOnboardingCohortEvents = {
|
||||
[N in EventName]: 'cohort' extends keyof EventMap[N] ? N : never
|
||||
}[EventName]
|
||||
type _OnboardingCohortRosterSync =
|
||||
_OnboardingCohortRoster extends _DerivedOnboardingCohortEvents
|
||||
? _DerivedOnboardingCohortEvents extends _OnboardingCohortRoster
|
||||
? true
|
||||
: never
|
||||
type _OnboardingCohortRosterSync = _OnboardingCohortRoster extends _DerivedOnboardingCohortEvents
|
||||
? _DerivedOnboardingCohortEvents extends _OnboardingCohortRoster
|
||||
? true
|
||||
: never
|
||||
: never
|
||||
const _onboardingCohortRosterSyncCheck: _OnboardingCohortRosterSync = true
|
||||
void _onboardingCohortRosterSyncCheck
|
||||
|
||||
|
||||
Reference in New Issue
Block a user