UNPKG

@extenshi/mcp

Version:

Extenshi MCP server — bring the extension catalog (search, security, market research) and pre-publish scanning into your AI tools

129 lines • 7.13 kB
/** * Opt-in usage telemetry — VENDORED, kept byte-identical between @extenshi/cli * and @extenshi/mcp (same pattern as validate-artifact.ts). Edit one, copy to * the other. * * Off unless the user said yes. Storing an ID on someone's machine and reading * it back for analytics needs prior consent (LSSI art. 22.2 / ePrivacy 5(3)), * so nothing is sent and no `anonId` is minted or read unless ONE of these holds: * - ~/.extenshi/config.json records a yes to the CURRENT question — both * "telemetry": true and "telemetryConsentVersion": TELEMETRY_CONSENT_VERSION * (written by the CLI's first-run question and by `extenshi telemetry on`); * - EXTENSHI_TELEMETRY is 1/true/on/yes — typed by hand, for one environment; * - the host called useSessionConsent(): the hosted connector, which runs on * our servers and asks every connection on its own consent screen. * No answer, a timeout, no TTY, CI and a headless MCP server all mean off. * DO_NOT_TRACK (https://consoledonottrack.com), EXTENSHI_TELEMETRY=0/false/off/no * and an emptied key (EXTENSHI_POSTHOG_KEY='') win over all three. * * What a report carries. TELEMETRY_PROMPT_TEXT (the CLI's telemetry-consent.ts) * is what the user agreed to, so keep it in step with this list: * - command/tool name, surface, package + Node version, os/arch, a CI bool * - the NAMES of CLI flags used (never their values — see flagsFromArgv) * - outcome, duration, exit code and a coarse error_kind * - for an unexpected failure, the error message and stack trace: the home * directory replaced by `~` (sanitizeError), the attached source lines * removed (stripSourceContext). A message can still quote user input. * Never artifact or file contents, manifest data, API keys or flag values. * * Identity is a random per-install UUID in ~/.extenshi/config.json (`anonId`): * an install, not a person, never linked client-side to the API key or account. * * Fail-soft: a throw in here is swallowed and can never break the command. */ import { PostHog } from 'posthog-node'; /** * Which wording of the consent question a saved `telemetry: true` answers. * * Version 1 carried no marker at all: it was the default-on `[Y/n]` prompt, * where an empty Enter counted as yes. That is not consent, so a `true` saved * without this marker is treated as "never asked" — off, and the CLI asks again. * A saved `false` needs no marker; a refusal stands whatever it was a refusal of. * * Bump it whenever the question changes what the user is agreeing to (a new * kind of data, a new recipient). Compared with `===` on purpose: a yes to a * later wording is not a yes to this one either. */ export declare const TELEMETRY_CONSENT_VERSION = 2; /** True only for a saved yes to the current question. See TELEMETRY_CONSENT_VERSION. */ export declare function consentRecorded(cfg: { telemetry?: unknown; telemetryConsentVersion?: unknown; }): boolean; /** Record the surface + version once at process startup. */ export declare function initTelemetry(opts: { surface: string; version: string; }): void; /** * Declare that consent is collected per connection by the host, not saved on * this machine. For the hosted connector only: it runs on our own servers, so * there is no user device to store an ID on, and every event it sends is gated * on that connection's answer to its consent screen (mcp-analytics.ts, * session-telemetry.ts). Must be called before the first event of the process. */ export declare function useSessionConsent(): void; /** * Off by default. The order is the contract: the switches that turn reporting * OFF are read first, so no way of turning it on can override a refusal. */ export declare function telemetryEnabled(): boolean; /** The existing install identity, without identifying or aliasing an account. */ export declare function telemetryAnonymousId(): string | undefined; /** * posthog-node opens the source file behind every stack frame and attaches the * lines around it to the report. A stack trace is what the user agreed to send; * the contents of files on their disk are not, so those lines are removed from * every event before it is queued. If that ever fails the event is dropped — * losing a crash report is the cheaper mistake. */ export declare function stripSourceContext<T extends { properties?: Record<string | number, unknown>; }>(event: T): T | null; /** * The shared posthog-node client, or null when telemetry is disabled. Exposed so * the MCP package's PostHog MCP Analytics instrumentation (mcp-analytics.ts) * rides this same client: one consent gate, one flush path (flushTelemetry). */ export declare function telemetryClient(): PostHog | null; /** Strip absolute home paths from any string before it leaves the machine. */ export declare function redactText(s: string): string; /** * Coarse error bucket. Driven by a numeric status when the error carries one * (ScanError `status`, tRPC `data.httpStatus`), else by message patterns (both * surfaces also throw plain Errors). Order matters — status first, then * transport, then semantic buckets. * * Follows the `cause` chain, because both surfaces re-throw a failure wrapped in * an error of their own so it renders for the caller — the MCP tool layer wraps * in fastmcp's `UserError` (readError() in its tools.ts) — and the wrapper's own * message can carry no status. The origin hangs off `cause`, so an * unclassifiable wrapper defers to what it wraps; without this, a BFF 500 behind * a wrapper reads as `unexpected`. */ export declare function classifyError(err: unknown): string; /** * The NAMES of long flags the user passed, with values stripped. `--out=/x` * becomes `--out`; the separate-token value of `--output /x` is never a `--` * token, so it is never collected. A token is kept only when what is left looks * like a flag name (letters, digits, dashes), so a value that happens to start * with `--` — a path, a URL, free text — is dropped rather than reported. */ export declare function flagsFromArgv(argv?: string[]): string[]; /** * `distinctId` overrides the per-install id. The CLI never passes it — * one install IS one identity there. The hosted MCP connector must: it is one * process serving many accounts, so the install id would collapse every user of * the service into a single person and re-mint on each redeploy. It passes the * authenticated account id instead (never an email — that stays in our own * database, see tools/extenshi-mcp-server/src/legal.ts). */ export declare function captureEvent(event: string, properties?: Record<string, unknown>, distinctId?: string): void; export declare function captureError(err: unknown, context?: Record<string, unknown>, distinctId?: string): void; /** * Flush buffered events and close the client. Hard-capped so a slow/hung * PostHog endpoint can never delay the command's exit. Safe to call when * telemetry is disabled (no-op) or more than once. */ export declare function flushTelemetry(): Promise<void>; //# sourceMappingURL=telemetry.d.ts.map