Skip to content

[ef-14] feat: add package_installed/uninstalled telemetry and fix dashboard path#13

Merged
NiveditJain merged 1 commit into
mainfrom
ef-14
Apr 6, 2026
Merged

[ef-14] feat: add package_installed/uninstalled telemetry and fix dashboard path#13
NiveditJain merged 1 commit into
mainfrom
ef-14

Conversation

@NiveditJain

@NiveditJain NiveditJain commented Apr 6, 2026

Copy link
Copy Markdown
Member

Summary

  • PostHog events: Add package_installed (postinstall) and package_uninstalled (preuninstall) npm lifecycle scripts — closes the gap vs claudeye; includes INIT_CWD guard so they don't fire during dev/CI installs
  • Auto-cleanup on uninstall: preuninstall.mjs removes failproofai hook entries from all Claude Code settings files (~/.claude/settings.json, project + local scopes) before the package is removed
  • Dashboard path bug fix: scripts/launch.ts was resolving .next/standalone/server.js relative to CWD — meaning the dashboard would crash when failproofai was run from any directory other than the package root (i.e., always after a real install). Fixed with import.meta.url-anchored absolute path.

Files changed

File Change
scripts/install-telemetry.mjs New — fetch-based PostHog helper for lifecycle scripts
scripts/postinstall.mjs New — fires package_installed, warns on stale hooks config
scripts/preuninstall.mjs New — cleans Claude Code hooks, fires package_uninstalled
package.json Add postinstall + preuninstall script entries
scripts/launch.ts Fix absolute path to .next/standalone/server.js

Test plan

  • TypeScript check passes (bunx tsc --noEmit — 0 errors)
  • ESLint passes (bun run lint — 0 errors, 1 pre-existing warning)
  • CI passes (quality, test × 4, build, e2e)
  • After merge: create GitHub Release v0.0.1-beta.1 to trigger publish workflow

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Installation and uninstallation event tracking has been implemented.
    • Post-installation hook validation now checks configuration status and provides setup guidance when needed.
  • Chores

    • Launch configuration has been optimized for improved reliability.
    • Automatic configuration cleanup now occurs during package uninstallation.

- Add scripts/postinstall.mjs — fires package_installed PostHog event on
  npm install; warns if hooks config exists but hooks aren't registered
- Add scripts/preuninstall.mjs — auto-removes failproofai hook entries from
  Claude Code settings on npm uninstall; fires package_uninstalled event
- Add scripts/install-telemetry.mjs — shared fetch-based PostHog helper for
  lifecycle scripts (no external deps, mirrors hook-telemetry pattern)
- Add postinstall/preuninstall entries to package.json scripts
- Guard both scripts with INIT_CWD check so they skip during dev/CI installs
- Fix scripts/launch.ts: resolve .next/standalone/server.js to an absolute
  path via import.meta.url — previously the dashboard would fail to start
  when failproofai was run from any directory other than the package root

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Free

Run ID: 713251af-f3a5-4d51-93b1-7308a358a4c2

📥 Commits

Reviewing files that changed from the base of the PR and between 45fb6e6 and b8a28dc.

📒 Files selected for processing (5)
  • package.json
  • scripts/install-telemetry.mjs
  • scripts/launch.ts
  • scripts/postinstall.mjs
  • scripts/preuninstall.mjs

📝 Walkthrough

Walkthrough

The changes introduce npm postinstall and preuninstall lifecycle hooks that integrate telemetry tracking and hook configuration management. A new telemetry module handles event submission to PostHog with stable instance identification. Hook configuration is validated during installation and cleaned up during uninstallation.

Changes

Cohort / File(s) Summary
Package Configuration
package.json
Added postinstall and preuninstall npm lifecycle script hooks pointing to new Node.js scripts.
Telemetry Infrastructure
scripts/install-telemetry.mjs
New module implementing PostHog telemetry with stable instance ID resolution across Linux, macOS, and Windows platforms, utilizing OS identifiers, environment variables, and fallback hashing of system properties.
Postinstall Lifecycle
scripts/postinstall.mjs
New postinstall hook validating hook configuration in ~/.failproofai/hooks-config.json and checking Claude Code hook registration, with best-effort telemetry tracking platform/architecture/hostname (hashed) and policy status.
Preuninstall Lifecycle
scripts/preuninstall.mjs
New preuninstall hook removing failproofai hook entries from Claude Code settings files (~/.claude/settings.json and project-local variants), with telemetry dispatch and error suppression to prevent uninstall blocking.
Build Infrastructure
scripts/launch.ts
Updated mode === "start" to resolve Next.js standalone server path absolutely relative to script module location using node:path and node:url imports.

Sequence Diagrams

sequenceDiagram
    actor npm
    participant postinstall as postinstall.mjs
    participant config as hooks-config.json
    participant claude as ~/.claude/settings.json
    participant telemetry as install-telemetry.mjs
    participant posthog as PostHog API

    npm->>postinstall: npm postinstall lifecycle
    postinstall->>config: read config & enabled policies
    postinstall->>claude: check for hook marker registration
    alt Hooks config found & policies enabled
        alt Hook marker not found in Claude
            postinstall->>postinstall: log warning for re-registration
        end
    end
    postinstall->>telemetry: trackInstallEvent(package_installed, {platform, arch, hostname_hash, hook_status})
    telemetry->>posthog: fetch capture with event & properties
    posthog-->>telemetry: response
    telemetry-->>postinstall: returns
    postinstall-->>npm: success (errors suppressed)
Loading
sequenceDiagram
    actor npm
    participant preuninstall as preuninstall.mjs
    participant settings as ~/.claude/settings.json<br/>.claude/settings.json<br/>.claude/settings.local.json
    participant telemetry as install-telemetry.mjs
    participant posthog as PostHog API

    npm->>preuninstall: npm preuninstall lifecycle
    loop For each settings file
        preuninstall->>settings: read settings
        preuninstall->>preuninstall: filter hooks by __failproofai_hook__ marker<br/>or command containing "failproofai --hook"
        preuninstall->>settings: remove matching hooks, clean empty keys
        preuninstall->>settings: rewrite JSON if changes made
    end
    preuninstall->>telemetry: trackInstallEvent(package_uninstalled, {platform, arch, hooks_removed_count})
    telemetry->>posthog: fetch capture with event & properties
    posthog-->>telemetry: response
    telemetry-->>preuninstall: awaited return
    preuninstall-->>npm: success (errors suppressed)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whiskers twitch with joy unbounded,
Telemetry paths are now grounded,
Install, track, and cleanup with grace,
Platform-aware hops through cyberspace! ✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@NiveditJain NiveditJain merged commit 6db955e into main Apr 6, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant