@marenfei/message-logger-plugin 0.1.2 → 0.1.3-beta.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.
Files changed (2) hide show
  1. package/index.ts +6 -49
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -465,64 +465,21 @@ export default function register(api: OpenClawPluginApi) {
465
465
  /**
466
466
  * Resolve the openclaw binary version.
467
467
  *
468
- * Priority:
469
- * 1. Build-time global __OPENCLAW_VERSION__ (injected by openclaw's own bundle)
470
- * 2. openclaw/package.json resolved via createRequire → "version" field
471
- * 3. npm global node_modules: execSync("npm root -g") + /openclaw/package.json
472
- * 4. /app/package.json → "version" field
473
- * 5. /app/dist/build-info.json → "version" field
474
- * fallback: "unknown"
468
+ * npm global node_modules: `npm root -g` + /openclaw/package.json
475
469
  */
476
470
  const openclawVersion = (() => {
477
- const readJsonSync = (filePath: string): Record<string, unknown> | null => {
478
- try {
479
- return JSON.parse(fsSync.readFileSync(filePath, "utf-8")) as Record<string, unknown>;
480
- } catch {
481
- return null;
482
- }
483
- };
484
-
485
- // 1. Build-time injected global
486
- const injected = (globalThis as Record<string, unknown>)["__OPENCLAW_VERSION__"];
487
- if (typeof injected === "string" && injected.trim()) {
488
- return injected.trim();
489
- }
490
-
491
- // 2. openclaw/package.json via createRequire
492
- try {
493
- const pkgPath = requireResolver.resolve("openclaw/package.json");
494
- const pkg = readJsonSync(pkgPath);
495
- if (typeof pkg?.version === "string" && (pkg.version as string).trim()) {
496
- return (pkg.version as string).trim();
497
- }
498
- } catch {
499
- // module not resolvable, fall through
500
- }
501
-
502
- // 3. npm global node_modules: `npm root -g` + /openclaw/package.json
503
471
  try {
504
472
  const { execSync } = requireResolver("node:child_process") as typeof import("node:child_process");
505
473
  const globalRoot = execSync("npm root -g", { encoding: "utf-8" }).trim();
506
- const pkg = readJsonSync(`${globalRoot}/openclaw/package.json`);
474
+ const pkg = JSON.parse(fsSync.readFileSync(`${globalRoot}/openclaw/package.json`, "utf-8")) as Record<string, unknown>;
507
475
  if (typeof pkg?.version === "string" && (pkg.version as string).trim()) {
508
476
  return (pkg.version as string).trim();
509
477
  }
510
- } catch {
511
- // npm not available or openclaw not installed globally, fall through
512
- }
513
-
514
- // 4. /app/package.json
515
- const pkg = readJsonSync("/app/package.json");
516
- if (typeof pkg?.version === "string" && (pkg.version as string).trim()) {
517
- return (pkg.version as string).trim();
518
- }
519
-
520
- // 5. /app/dist/build-info.json
521
- const info = readJsonSync("/app/dist/build-info.json");
522
- if (typeof info?.version === "string" && (info.version as string).trim()) {
523
- return (info.version as string).trim();
478
+ } catch (err){
479
+ // npm not available or openclaw not installed globally
480
+ const message = err instanceof Error ? err.message : String(err);
481
+ api.logger.warn(`openclawVersion resolve error: ${message}`);
524
482
  }
525
-
526
483
  return "unknown";
527
484
  })();
528
485
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marenfei/message-logger-plugin",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-beta.1",
4
4
  "description": "OpenClaw message logger plugin using plugin hooks",
5
5
  "type": "module",
6
6
  "main": "./index.ts",