@theholocron/cli 4.14.0 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -5823,30 +5823,19 @@ async function writeWorkflowFile(repoRoot, filename, content) {
5823
5823
  //#endregion
5824
5824
  //#region src/telemetry/posthog-sink.ts
5825
5825
  /**
5826
- * `PostHogSink` — the **only** `posthog-node` import in the CLI. Product
5827
- * analytics (usage, adoption, retention), activated self-contained per ADR-0008:
5826
+ * `PostHogSink` — the **only** `posthog-node` call site. A portable
5827
+ * `AnalyticsSink` adapter: usage, adoption, retention. It reads no environment
5828
+ * and ships no credentials — the constructor takes a resolved `key` + `host`;
5829
+ * the caller (the CLI's `telemetry.ts`, via `telemetry/resolve.ts`) owns the
5830
+ * env chain and the fallback. An empty `key` is the caller's signal to install
5831
+ * a `NoopAnalyticsSink` instead — it is never passed here.
5828
5832
  *
5829
- * HOLOCRON_POSTHOG_PROJECT_TOKEN → POSTHOG_PROJECT_TOKEN → built-in fallback key
5830
- * HOLOCRON_POSTHOG_HOST → POSTHOG_HOST → https://us.i.posthog.com
5831
- *
5832
- * The built-in fallback is an ingest-only project write key (`phc_…`) — it can
5833
- * capture events, never read data — so it ships in the published package, the
5834
- * same risk model as the hard-coded Sentry DSN. {@link resolvePostHogKey}
5835
- * returning `""` is how the caller decides to install a `NoopAnalyticsSink`.
5833
+ * Destined for `@theholocron/observability/analytics` (#635).
5836
5834
  */
5837
- const FALLBACK_POSTHOG_PROJECT_TOKEN = "phc_AC4vFCvYzwnzmG7Vg5nEc3PZKZztoPyfKp4Lb9BbXcLK";
5838
- const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
5839
- /** Resolve the PostHog project key. `""` → usage analytics disabled. */
5840
- function resolvePostHogKey() {
5841
- return env.get("HOLOCRON_POSTHOG_PROJECT_TOKEN") ?? env.get("POSTHOG_PROJECT_TOKEN") ?? FALLBACK_POSTHOG_PROJECT_TOKEN;
5842
- }
5843
- function resolvePostHogHost() {
5844
- return env.get("HOLOCRON_POSTHOG_HOST") ?? env.get("POSTHOG_HOST") ?? DEFAULT_POSTHOG_HOST;
5845
- }
5846
5835
  var PostHogSink = class {
5847
5836
  #client;
5848
- constructor() {
5849
- this.#client = new PostHog(resolvePostHogKey(), { host: resolvePostHogHost() });
5837
+ constructor(config) {
5838
+ this.#client = new PostHog(config.key, { host: config.host });
5850
5839
  }
5851
5840
  identify(distinctId, props) {
5852
5841
  this.#client.identify({
@@ -5884,12 +5873,42 @@ function redactObject(value) {
5884
5873
  return JSON.parse(redact(JSON.stringify(value)));
5885
5874
  }
5886
5875
  //#endregion
5887
- //#region src/telemetry/sentry-sink.ts
5876
+ //#region src/telemetry/resolve.ts
5877
+ /**
5878
+ * Holocron-specific credential resolution for the telemetry sinks — the env
5879
+ * chain plus Holocron's own shipped fallbacks. This is **CLI policy**, not part
5880
+ * of the portable adapter set: `sentry-sink.ts` / `posthog-sink.ts` take a
5881
+ * resolved DSN / key and never read the environment. When the adapters move to
5882
+ * `@theholocron/observability` (#635) this module stays here.
5883
+ *
5884
+ * errors: HOLOCRON_SENTRY_DSN → SENTRY_DSN → FALLBACK_DSN
5885
+ * analytics: HOLOCRON_POSTHOG_PROJECT_TOKEN → POSTHOG_PROJECT_TOKEN → FALLBACK_POSTHOG_PROJECT_TOKEN
5886
+ * host: HOLOCRON_POSTHOG_HOST → POSTHOG_HOST → DEFAULT_POSTHOG_HOST
5887
+ *
5888
+ * The `SENTRY_DSN` / `POSTHOG_PROJECT_TOKEN` fallbacks are the vendor-native
5889
+ * names a consumer repo sets to route CLI telemetry to its own project. The
5890
+ * built-in fallbacks are ingest-only keys — publishable by design, same risk
5891
+ * model as ADR-0007 / ADR-0008.
5892
+ */
5893
+ /** Holocron's own Sentry project — the fallback when no env var points elsewhere. */
5888
5894
  const FALLBACK_DSN = "https://95cbb72ad5636c94e119a5405ee8f55f@o4508238154104832.ingest.us.sentry.io/4511810950791168";
5895
+ /** Holocron's own PostHog project write key — ingest-only. */
5896
+ const FALLBACK_POSTHOG_PROJECT_TOKEN = "phc_AC4vFCvYzwnzmG7Vg5nEc3PZKZztoPyfKp4Lb9BbXcLK";
5897
+ const DEFAULT_POSTHOG_HOST = "https://us.i.posthog.com";
5889
5898
  /** Resolve the Sentry DSN. `""` → error telemetry disabled. */
5890
5899
  function resolveDsn() {
5891
5900
  return env.get("HOLOCRON_SENTRY_DSN") ?? env.get("SENTRY_DSN") ?? FALLBACK_DSN;
5892
5901
  }
5902
+ /** Resolve the PostHog project key. `""` → usage analytics disabled. */
5903
+ function resolvePostHogKey() {
5904
+ return env.get("HOLOCRON_POSTHOG_PROJECT_TOKEN") ?? env.get("POSTHOG_PROJECT_TOKEN") ?? FALLBACK_POSTHOG_PROJECT_TOKEN;
5905
+ }
5906
+ /** Resolve the PostHog ingest host. */
5907
+ function resolvePostHogHost() {
5908
+ return env.get("HOLOCRON_POSTHOG_HOST") ?? env.get("POSTHOG_HOST") ?? DEFAULT_POSTHOG_HOST;
5909
+ }
5910
+ //#endregion
5911
+ //#region src/telemetry/sentry-sink.ts
5893
5912
  /** `beforeSend` — token-shaped strings never leave the process. */
5894
5913
  function scrubError(event, _hint) {
5895
5914
  return redactObject(event);
@@ -5897,7 +5916,7 @@ function scrubError(event, _hint) {
5897
5916
  var SentrySink = class {
5898
5917
  init(ctx) {
5899
5918
  Sentry.init({
5900
- dsn: resolveDsn(),
5919
+ dsn: ctx.dsn,
5901
5920
  release: ctx.release,
5902
5921
  environment: ctx.environment,
5903
5922
  tracesSampleRate: 1,
@@ -5960,9 +5979,10 @@ var NoopAnalyticsSink = class {
5960
5979
  * `posthog-node` call sites, and a `Noop*Sink` is installed when telemetry is
5961
5980
  * off. Same seam `@theholocron/logger` uses for Pino.
5962
5981
  *
5963
- * Activation is env-var + shipped-fallback, resolved inside each sink. The
5964
- * single kill switch is `HOLOCRON_TELEMETRY=false` (legacy alias
5965
- * `NO_HOLOCRON_TELEMETRY`); see ADR-0007 / ADR-0008.
5982
+ * Activation is env-var + shipped-fallback, resolved here (`telemetry/resolve.ts`)
5983
+ * and passed to the sink — the adapters read no environment. The single kill
5984
+ * switch is `HOLOCRON_TELEMETRY=false` (legacy alias `NO_HOLOCRON_TELEMETRY`);
5985
+ * see ADR-0007 / ADR-0008.
5966
5986
  */
5967
5987
  let errors = new NoopErrorSink();
5968
5988
  let analytics = new NoopAnalyticsSink();
@@ -5998,9 +6018,11 @@ function baseProps() {
5998
6018
  };
5999
6019
  }
6000
6020
  function init(version) {
6001
- if (isEnabled() && resolveDsn() !== "") {
6021
+ const dsn = resolveDsn();
6022
+ if (isEnabled() && dsn !== "") {
6002
6023
  errors = new SentrySink();
6003
6024
  errors.init({
6025
+ dsn,
6004
6026
  release: `holocron@${version}`,
6005
6027
  environment: env.get("CI") ? "ci" : "local",
6006
6028
  tags: {
@@ -6010,8 +6032,12 @@ function init(version) {
6010
6032
  }
6011
6033
  });
6012
6034
  }
6013
- if (isEnabled() && resolvePostHogKey() !== "") {
6014
- analytics = new PostHogSink();
6035
+ const posthogKey = resolvePostHogKey();
6036
+ if (isEnabled() && posthogKey !== "") {
6037
+ analytics = new PostHogSink({
6038
+ key: posthogKey,
6039
+ host: resolvePostHogHost()
6040
+ });
6015
6041
  analytics.identify(machineId(), {
6016
6042
  ci: Boolean(env.get("CI")),
6017
6043
  os: process.platform,