@bike4mind/cli 0.2.31-b4m-cli-undo-command.19493 → 0.2.31-b4m-cli-undo-command.19535

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.
@@ -5,6 +5,7 @@ var Logger = class _Logger {
5
5
  static globalInstance = new _Logger();
6
6
  metadata = {};
7
7
  logInJson;
8
+ prettyPrint;
8
9
  minLevel;
9
10
  // Log level hierarchy (higher number = more severe)
10
11
  static LOG_LEVELS = {
@@ -13,15 +14,112 @@ var Logger = class _Logger {
13
14
  warn: 2,
14
15
  error: 3
15
16
  };
17
+ // ANSI color codes for pretty printing
18
+ static COLORS = {
19
+ debug: "\x1B[36m",
20
+ // Cyan
21
+ info: "\x1B[32m",
22
+ // Green
23
+ warn: "\x1B[33m",
24
+ // Yellow
25
+ error: "\x1B[31m",
26
+ // Red
27
+ reset: "\x1B[0m",
28
+ dim: "\x1B[2m"
29
+ };
30
+ // Level labels for pretty printing (padded for alignment)
31
+ static LEVEL_LABELS = {
32
+ debug: "DEBUG",
33
+ info: " INFO",
34
+ warn: " WARN",
35
+ error: "ERROR"
36
+ };
37
+ // Indentation constants for pretty printing
38
+ static INDENT = " ";
39
+ static NESTED_INDENT = " ";
16
40
  constructor(options = {}) {
17
- const { metadata = {}, logInJson = process.env.LOG_JSON === "true" || !(process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development"), minLevel = process.env.LOG_LEVEL || "info" } = options;
41
+ const isLocalDev = process.env.IS_LOCAL === "true" || process.env.NODE_ENV === "development" || process.env.SST_LIVE === "true";
42
+ const { metadata = {}, logInJson = process.env.LOG_JSON === "true" || !isLocalDev, prettyPrint = isLocalDev && process.env.LOG_PRETTY !== "false", minLevel = process.env.LOG_LEVEL || "info" } = options;
18
43
  this.metadata = metadata;
19
44
  this.logInJson = logInJson;
45
+ this.prettyPrint = prettyPrint;
20
46
  this.minLevel = minLevel;
21
47
  }
22
48
  shouldLog(level) {
23
49
  return _Logger.LOG_LEVELS[level] >= _Logger.LOG_LEVELS[this.minLevel];
24
50
  }
51
+ /**
52
+ * Safely stringify a value, handling circular references
53
+ */
54
+ safeStringify(value, indent) {
55
+ try {
56
+ return JSON.stringify(value, null, indent);
57
+ } catch {
58
+ return "[Circular]";
59
+ }
60
+ }
61
+ /**
62
+ * Parse log arguments to extract message and optional metadata
63
+ */
64
+ parseArgs(args, errorAware = false) {
65
+ if (args.length === 0) {
66
+ return { message: "" };
67
+ }
68
+ const lastArg = args[args.length - 1];
69
+ const hasMetadata = args.length > 1 && typeof lastArg === "object" && lastArg !== null && !Array.isArray(lastArg) && !(lastArg instanceof Error);
70
+ const metadata = hasMetadata ? lastArg : void 0;
71
+ const messageArgs = hasMetadata ? args.slice(0, -1) : args;
72
+ const message = messageArgs.map((a) => {
73
+ if (errorAware && a instanceof Error) {
74
+ return a.stack || a.message;
75
+ }
76
+ return typeof a === "string" ? a : this.safeStringify(a);
77
+ }).join(" ");
78
+ return { message, metadata };
79
+ }
80
+ /**
81
+ * Output a log message using the appropriate format
82
+ */
83
+ output(level, consoleFn, message, metadata) {
84
+ const allMetadata = { ...this.metadata, ...metadata };
85
+ if (this.logInJson) {
86
+ consoleFn(this.safeStringify({ ...allMetadata, severity: level, message }));
87
+ } else if (this.prettyPrint) {
88
+ consoleFn(this.formatPretty(level, message, metadata));
89
+ } else {
90
+ const metadataKeys = Object.keys(allMetadata);
91
+ if (metadataKeys.length > 0) {
92
+ consoleFn(message, allMetadata);
93
+ } else {
94
+ consoleFn(message);
95
+ }
96
+ }
97
+ }
98
+ /**
99
+ * Format a log message with pino-pretty-like output for local development
100
+ */
101
+ formatPretty(level, message, metadata) {
102
+ const { reset, dim } = _Logger.COLORS;
103
+ const color = _Logger.COLORS[level];
104
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
105
+ const parts = [];
106
+ parts.push(`${dim}[${timestamp}]${reset} ${color}${_Logger.LEVEL_LABELS[level]}${reset} ${message}`);
107
+ const allMetadata = { ...this.metadata, ...metadata };
108
+ const metadataKeys = Object.keys(allMetadata);
109
+ if (metadataKeys.length > 0) {
110
+ for (const key of metadataKeys) {
111
+ const value = allMetadata[key];
112
+ if (typeof value === "object" && value !== null) {
113
+ const jsonStr = this.safeStringify(value, 2);
114
+ const indentedJson = jsonStr.split("\n").map((line, idx) => idx === 0 ? line : _Logger.NESTED_INDENT + line).join("\n");
115
+ parts.push(`${_Logger.INDENT}${dim}${key}:${reset} ${indentedJson}`);
116
+ } else {
117
+ parts.push(`${_Logger.INDENT}${dim}${key}:${reset} ${value}`);
118
+ }
119
+ }
120
+ }
121
+ return parts.join("\n");
122
+ }
25
123
  resetMetadata() {
26
124
  this.metadata = {};
27
125
  return this;
@@ -33,6 +131,7 @@ var Logger = class _Logger {
33
131
  ...metadata
34
132
  },
35
133
  logInJson: this.logInJson,
134
+ prettyPrint: this.prettyPrint,
36
135
  minLevel: this.minLevel
37
136
  });
38
137
  }
@@ -49,47 +148,26 @@ var Logger = class _Logger {
49
148
  debug(...args) {
50
149
  if (!this.shouldLog("debug"))
51
150
  return;
52
- const message = args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ");
53
- if (this.logInJson) {
54
- console.debug(JSON.stringify({ ...this.metadata, severity: "debug", message }));
55
- } else {
56
- console.debug(message);
57
- }
151
+ const { message, metadata } = this.parseArgs(args);
152
+ this.output("debug", console.debug, message, metadata);
58
153
  }
59
154
  info(...args) {
60
155
  if (!this.shouldLog("info"))
61
156
  return;
62
- const message = args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ");
63
- if (this.logInJson) {
64
- console.info(JSON.stringify({ ...this.metadata, severity: "info", message }));
65
- } else {
66
- console.info(message);
67
- }
157
+ const { message, metadata } = this.parseArgs(args);
158
+ this.output("info", console.info, message, metadata);
68
159
  }
69
160
  warn(...args) {
70
161
  if (!this.shouldLog("warn"))
71
162
  return;
72
- const message = args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ");
73
- if (this.logInJson) {
74
- console.warn(JSON.stringify({ ...this.metadata, severity: "warn", message }));
75
- } else {
76
- console.warn(message);
77
- }
163
+ const { message, metadata } = this.parseArgs(args);
164
+ this.output("warn", console.warn, message, metadata);
78
165
  }
79
166
  error(...args) {
80
167
  if (!this.shouldLog("error"))
81
168
  return;
82
- const message = args.map((a) => {
83
- if (a instanceof Error) {
84
- return a.stack || a.message;
85
- }
86
- return typeof a === "string" ? a : JSON.stringify(a);
87
- }).join(" ");
88
- if (this.logInJson) {
89
- console.error(JSON.stringify({ ...this.metadata, severity: "error", message }));
90
- } else {
91
- console.error(message);
92
- }
169
+ const { message, metadata } = this.parseArgs(args, true);
170
+ this.output("error", console.error, message, metadata);
93
171
  }
94
172
  /*
95
173
  * Global logger instance handling:
@@ -160,7 +238,7 @@ var notifyEventLogsToSlack = async ({ event, stage, slackUrl, throttlingSlackUrl
160
238
  if (!allowedStages.includes(stage))
161
239
  return;
162
240
  const logEvents = logData.logEvents;
163
- const { notificationDeduplicator: notificationDeduplicator2 } = await import("./notificationDeduplicator-UTHJHMSZ.js");
241
+ const { notificationDeduplicator: notificationDeduplicator2 } = await import("./notificationDeduplicator-HUC53NEW.js");
164
242
  for (const logEvent of logEvents) {
165
243
  try {
166
244
  let message;
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ fetchLatestVersion,
4
+ forceCheckForUpdate,
5
+ package_default
6
+ } from "../chunk-M2QCFHVX.js";
7
+
8
+ // src/commands/doctorCommand.ts
9
+ import { execSync } from "child_process";
10
+ import { existsSync, constants } from "fs";
11
+ import { promises as fsPromises } from "fs";
12
+ import path from "path";
13
+ import { homedir } from "os";
14
+ async function handleDoctorCommand() {
15
+ console.log("B4M CLI Doctor\n");
16
+ console.log("Running diagnostics...\n");
17
+ const results = [];
18
+ const nodeVersion = process.version;
19
+ const nodeMajor = parseInt(nodeVersion.slice(1).split(".")[0], 10);
20
+ if (nodeMajor >= 18) {
21
+ results.push({ name: "Node.js version", status: "pass", message: `${nodeVersion} (>= 18 required)` });
22
+ } else {
23
+ results.push({
24
+ name: "Node.js version",
25
+ status: "fail",
26
+ message: `${nodeVersion} (>= 18 required, please upgrade)`
27
+ });
28
+ }
29
+ const latestVersion = await fetchLatestVersion();
30
+ if (latestVersion) {
31
+ results.push({ name: "NPM registry", status: "pass", message: `Accessible (latest: v${latestVersion})` });
32
+ } else {
33
+ results.push({ name: "NPM registry", status: "fail", message: "Not accessible \u2014 check your internet connection" });
34
+ }
35
+ const currentVersion = package_default.version;
36
+ const updateResult = await forceCheckForUpdate(currentVersion);
37
+ if (updateResult) {
38
+ if (updateResult.updateAvailable) {
39
+ results.push({
40
+ name: "Version",
41
+ status: "warn",
42
+ message: `v${currentVersion} installed, v${updateResult.latestVersion} available. Run: b4m update`
43
+ });
44
+ } else {
45
+ results.push({ name: "Version", status: "pass", message: `v${currentVersion} (latest)` });
46
+ }
47
+ }
48
+ try {
49
+ const npmPrefix = execSync("npm config get prefix", { encoding: "utf-8", timeout: 1e4 }).trim();
50
+ try {
51
+ await fsPromises.access(npmPrefix, constants.W_OK);
52
+ results.push({ name: "Global npm path", status: "pass", message: `${npmPrefix} (writable)` });
53
+ } catch {
54
+ results.push({
55
+ name: "Global npm path",
56
+ status: "warn",
57
+ message: `${npmPrefix} (not writable \u2014 may need sudo for updates)`
58
+ });
59
+ }
60
+ } catch {
61
+ results.push({ name: "Global npm path", status: "warn", message: "Could not determine npm prefix" });
62
+ }
63
+ const configFile = path.join(homedir(), ".bike4mind", "config.json");
64
+ if (existsSync(configFile)) {
65
+ results.push({ name: "Config file", status: "pass", message: configFile });
66
+ } else {
67
+ results.push({ name: "Config file", status: "warn", message: `Not found at ${configFile}` });
68
+ }
69
+ console.log("Results:\n");
70
+ for (const result of results) {
71
+ const icon = result.status === "pass" ? "\x1B[32m\u2713\x1B[0m" : result.status === "warn" ? "\x1B[33m!\x1B[0m" : "\x1B[31m\u2717\x1B[0m";
72
+ console.log(` ${icon} ${result.name}: ${result.message}`);
73
+ }
74
+ const failures = results.filter((r) => r.status === "fail");
75
+ const warnings = results.filter((r) => r.status === "warn");
76
+ console.log("");
77
+ if (failures.length > 0) {
78
+ console.log(`${failures.length} issue(s) found.`);
79
+ } else if (warnings.length > 0) {
80
+ console.log(`All checks passed with ${warnings.length} warning(s).`);
81
+ } else {
82
+ console.log("All checks passed.");
83
+ }
84
+ }
85
+ export {
86
+ handleDoctorCommand
87
+ };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  ConfigStore
4
- } from "../chunk-LBTTUQJM.js";
4
+ } from "../chunk-32PKF3N7.js";
5
5
 
6
6
  // src/commands/mcpCommand.ts
7
7
  async function handleMcpCommand(subcommand, argv) {
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ forceCheckForUpdate,
4
+ package_default
5
+ } from "../chunk-M2QCFHVX.js";
6
+
7
+ // src/commands/updateCommand.ts
8
+ import { execSync } from "child_process";
9
+ async function handleUpdateCommand() {
10
+ const currentVersion = package_default.version;
11
+ console.log(`Current version: v${currentVersion}`);
12
+ console.log("Checking for updates...\n");
13
+ const result = await forceCheckForUpdate(currentVersion);
14
+ if (!result) {
15
+ console.error("Failed to check for updates. Check your internet connection.");
16
+ process.exit(1);
17
+ }
18
+ if (!result.updateAvailable) {
19
+ console.log(`Already on the latest version (v${currentVersion}).`);
20
+ return;
21
+ }
22
+ console.log(`Update available: v${currentVersion} \u2192 v${result.latestVersion}
23
+ `);
24
+ console.log("Installing update...\n");
25
+ try {
26
+ execSync("npm install -g @bike4mind/cli@latest", {
27
+ stdio: "inherit",
28
+ timeout: 12e4
29
+ });
30
+ console.log(`
31
+ Successfully updated to v${result.latestVersion}.`);
32
+ } catch {
33
+ console.error("\nUpdate failed. Try running manually:");
34
+ console.error(" npm install -g @bike4mind/cli@latest");
35
+ console.error("\nIf you get permission errors, try:");
36
+ console.error(" sudo npm install -g @bike4mind/cli@latest");
37
+ process.exit(1);
38
+ }
39
+ }
40
+ export {
41
+ handleUpdateCommand
42
+ };
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createFabFile,
4
+ createFabFileSchema
5
+ } from "./chunk-ERV5G6MX.js";
6
+ import "./chunk-3SPW5FYJ.js";
7
+ import "./chunk-NI22LIK3.js";
8
+ import "./chunk-PFBYGCOW.js";
9
+ export {
10
+ createFabFile,
11
+ createFabFileSchema
12
+ };