@base44-preview/cli 0.0.25-pr.153.cbfcf39 → 0.0.25-pr.156.f6042c0

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.
Files changed (3) hide show
  1. package/bin/run.js +23 -2
  2. package/dist/index.js +86 -15
  3. package/package.json +4 -1
package/bin/run.js CHANGED
@@ -1,19 +1,40 @@
1
1
  #!/usr/bin/env node
2
+ import { program, CLIExitError, errorReporter } from "../dist/index.js";
2
3
 
3
4
  // Disable Clack spinners and animations in non-interactive environments.
4
5
  // Clack only checks the CI env var, so we set it when stdin/stdout aren't TTYs.
5
6
  if (!process.stdin.isTTY || !process.stdout.isTTY) {
6
- process.env.CI = 'true';
7
+ process.env.CI = "true";
7
8
  }
8
9
 
9
- import { program, CLIExitError } from "../dist/index.js";
10
+ // Initialize error reporter
11
+ // The API key should be provided via environment variable
12
+ const posthogApiKey = process.env.POSTHOG_API_KEY;
13
+ if (posthogApiKey) {
14
+ errorReporter.initialize(posthogApiKey, process.env.POSTHOG_HOST);
15
+ }
10
16
 
11
17
  try {
12
18
  await program.parseAsync();
13
19
  } catch (error) {
20
+ // Report the error to PostHog if it's not a controlled exit
21
+ if (!(error instanceof CLIExitError)) {
22
+ await errorReporter.captureException(error, {
23
+ command: process.argv.slice(2).join(" "),
24
+ node_version: process.version,
25
+ platform: process.platform,
26
+ });
27
+ }
28
+
29
+ // Ensure PostHog events are sent before exiting
30
+ await errorReporter.shutdown();
31
+
14
32
  if (error instanceof CLIExitError) {
15
33
  process.exit(error.code);
16
34
  }
17
35
  console.error(error);
18
36
  process.exit(1);
37
+ } finally {
38
+ // Always shutdown error reporter on normal exit too
39
+ await errorReporter.shutdown();
19
40
  }
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ import tty from "node:tty";
26
26
  import { scheduler, setImmediate as setImmediate$1, setTimeout as setTimeout$1 } from "node:timers/promises";
27
27
  import { serialize } from "node:v8";
28
28
  import { Buffer as Buffer$2 } from "node:buffer";
29
+ import { PostHog } from "posthog-node";
29
30
 
30
31
  //#region rolldown:runtime
31
32
  var __create = Object.create;
@@ -38473,7 +38474,7 @@ async function executeCreate({ template, name: rawName, description, projectPath
38473
38474
  id: projectId,
38474
38475
  projectRoot: resolvedPath
38475
38476
  });
38476
- const { project, entities, agents } = await readProjectConfig(resolvedPath);
38477
+ const { project, entities } = await readProjectConfig(resolvedPath);
38477
38478
  let finalAppUrl;
38478
38479
  if (entities.length > 0) {
38479
38480
  let shouldPushEntities;
@@ -38488,19 +38489,6 @@ async function executeCreate({ template, name: rawName, description, projectPath
38488
38489
  errorMessage: "Failed to push data models"
38489
38490
  });
38490
38491
  }
38491
- if (agents.length > 0) {
38492
- let shouldPushAgents;
38493
- if (isInteractive) {
38494
- const result = await ye({ message: "Configure AI agent? (This sets up the AI assistant included in the template)" });
38495
- shouldPushAgents = !pD(result) && result;
38496
- } else shouldPushAgents = !!deploy;
38497
- if (shouldPushAgents) await runTask(`Configuring ${agents.length} AI agent${agents.length > 1 ? "s" : ""}...`, async () => {
38498
- await pushAgents(agents);
38499
- }, {
38500
- successMessage: theme.colors.base44Orange("AI agent configured successfully"),
38501
- errorMessage: "Failed to configure AI agent"
38502
- });
38503
- }
38504
38492
  if (project.site) {
38505
38493
  const { installCommand, buildCommand, outputDirectory } = project.site;
38506
38494
  let shouldDeploy;
@@ -39299,4 +39287,87 @@ program.addCommand(functionsDeployCommand);
39299
39287
  program.addCommand(siteDeployCommand);
39300
39288
 
39301
39289
  //#endregion
39302
- export { CLIExitError, program };
39290
+ //#region src/cli/error-reporter.ts
39291
+ /**
39292
+ * Error reporter using PostHog for CLI executions.
39293
+ * Designed for short-running CLI tools with proper shutdown handling.
39294
+ */
39295
+ var ErrorReporter = class {
39296
+ client = null;
39297
+ isEnabled = false;
39298
+ shutdownPromise = null;
39299
+ /**
39300
+ * Initialize the error reporter with PostHog configuration.
39301
+ * @param apiKey - PostHog API key
39302
+ * @param host - PostHog host URL (optional, defaults to PostHog cloud)
39303
+ */
39304
+ initialize(apiKey, host) {
39305
+ if (!apiKey) {
39306
+ console.warn("PostHog API key not provided. Error reporting disabled.");
39307
+ return;
39308
+ }
39309
+ try {
39310
+ this.client = new PostHog(apiKey, {
39311
+ host: host || "https://us.i.posthog.com",
39312
+ flushAt: 1,
39313
+ flushInterval: 0
39314
+ });
39315
+ this.isEnabled = true;
39316
+ } catch (error) {
39317
+ console.error("Failed to initialize PostHog client:", error);
39318
+ this.isEnabled = false;
39319
+ }
39320
+ }
39321
+ /**
39322
+ * Capture an exception and report it to PostHog.
39323
+ * @param error - The error to capture
39324
+ * @param context - Optional additional context about the error
39325
+ */
39326
+ async captureException(error, context) {
39327
+ if (!this.isEnabled || !this.client) return;
39328
+ try {
39329
+ const properties = {
39330
+ error_name: error.name,
39331
+ error_message: error.message,
39332
+ error_stack: error.stack,
39333
+ ...context
39334
+ };
39335
+ this.client.capture({
39336
+ distinctId: "cli-user",
39337
+ event: "cli_error",
39338
+ properties
39339
+ });
39340
+ await this.client.flush();
39341
+ } catch (captureError) {
39342
+ console.error("Failed to capture exception:", captureError);
39343
+ }
39344
+ }
39345
+ /**
39346
+ * Shutdown the error reporter and ensure all events are sent.
39347
+ * MUST be called before CLI exits to ensure events are flushed.
39348
+ */
39349
+ async shutdown() {
39350
+ if (!this.client || this.shutdownPromise) return this.shutdownPromise || Promise.resolve();
39351
+ this.shutdownPromise = (async () => {
39352
+ try {
39353
+ await this.client.shutdown();
39354
+ } catch (error) {
39355
+ console.error("Error during PostHog shutdown:", error);
39356
+ } finally {
39357
+ this.isEnabled = false;
39358
+ this.client = null;
39359
+ }
39360
+ })();
39361
+ return this.shutdownPromise;
39362
+ }
39363
+ /**
39364
+ * Check if error reporting is enabled.
39365
+ */
39366
+ get enabled() {
39367
+ return this.isEnabled;
39368
+ }
39369
+ };
39370
+ const errorReporter = new ErrorReporter();
39371
+
39372
+ //#endregion
39373
+ export { CLIExitError, errorReporter, program };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/cli",
3
- "version": "0.0.25-pr.153.cbfcf39",
3
+ "version": "0.0.25-pr.156.f6042c0",
4
4
  "description": "Base44 CLI - Unified interface for managing Base44 applications",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,6 +31,9 @@
31
31
  "type": "git",
32
32
  "url": "https://github.com/base44/cli"
33
33
  },
34
+ "dependencies": {
35
+ "posthog-node": "^4.2.1"
36
+ },
34
37
  "devDependencies": {
35
38
  "@clack/prompts": "^0.11.0",
36
39
  "@stylistic/eslint-plugin": "^5.6.1",