@zshuangmu/agenthub 0.3.0 → 0.3.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zshuangmu/agenthub",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "AI Agent 打包与分发平台 - 一句话打包上传,一键下载获得能力",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/cli.js CHANGED
@@ -489,6 +489,26 @@ async function main() {
489
489
  const causeMsg = err.cause?.errors?.[0]?.message || err.cause?.message || "";
490
490
  const detailMsg = causeMsg ? `${err.message}\n 原因: ${causeMsg}` : err.message;
491
491
  console.error(`\n${error(`${symbols.error} 错误:`)} ${detailMsg}`);
492
+
493
+ // 提供友好的解决建议
494
+ const errMsg = err.message.toLowerCase();
495
+ if (errMsg.includes("not found") || errMsg.includes("does not exist") || errMsg.includes("enoent")) {
496
+ console.log(`\n${warning("建议:")}`);
497
+ console.log(` - 检查文件路径是否正确`);
498
+ console.log(` - 确认 workspace 目录存在`);
499
+ console.log(` - 运行 ${highlight("agenthub --help")} 查看命令用法`);
500
+ } else if (errMsg.includes("permission") || errMsg.includes("eacces")) {
501
+ console.log(`\n${warning("建议:")}`);
502
+ console.log(` - 检查文件权限`);
503
+ console.log(` - 尝试使用 ${highlight("sudo")} 命令`);
504
+ } else if (errMsg.includes("network") || errMsg.includes("econnrefused") || errMsg.includes("timeout")) {
505
+ console.log(`\n${warning("建议:")}`);
506
+ console.log(` - 检查网络连接`);
507
+ console.log(` - 确认服务器地址正确`);
508
+ console.log(` - 使用 ${highlight("--registry")} 指定本地 registry`);
509
+ }
510
+
511
+ console.log(`\n${muted("如需更多帮助,运行: agenthub <command> --help")}`);
492
512
  process.exitCode = 1;
493
513
  }
494
514
  }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Debug Logger
3
+ * 性能日志工具,用于调试和性能分析
4
+ */
5
+
6
+ const DEBUG = process.env.AGENTHUB_DEBUG === "true" || process.env.AGENTHUB_DEBUG === "1";
7
+
8
+ /**
9
+ * 计时器存储
10
+ */
11
+ const timers = new Map();
12
+
13
+ /**
14
+ * 开始计时
15
+ * @param {string} label - 计时标签
16
+ */
17
+ export function time(label) {
18
+ if (!DEBUG) return;
19
+ timers.set(label, Date.now());
20
+ }
21
+
22
+ /**
23
+ * 结束计时并输出
24
+ * @param {string} label - 计时标签
25
+ * @returns {number|null} 耗时毫秒数
26
+ */
27
+ export function timeEnd(label) {
28
+ if (!DEBUG) return null;
29
+ const start = timers.get(label);
30
+ if (!start) return null;
31
+ const elapsed = Date.now() - start;
32
+ timers.delete(label);
33
+ console.log(`[DEBUG] ${label}: ${elapsed}ms`);
34
+ return elapsed;
35
+ }
36
+
37
+ /**
38
+ * 输出调试日志
39
+ * @param {string} message - 日志消息
40
+ * @param {...any} args - 额外参数
41
+ */
42
+ export function debug(message, ...args) {
43
+ if (!DEBUG) return;
44
+ const timestamp = new Date().toISOString().split("T")[1].slice(0, 12);
45
+ console.log(`[DEBUG ${timestamp}] ${message}`, ...args);
46
+ }
47
+
48
+ /**
49
+ * 输出警告日志
50
+ * @param {string} message - 日志消息
51
+ * @param {...any} args - 额外参数
52
+ */
53
+ export function warn(message, ...args) {
54
+ if (!DEBUG) return;
55
+ const timestamp = new Date().toISOString().split("T")[1].slice(0, 12);
56
+ console.warn(`[WARN ${timestamp}] ${message}`, ...args);
57
+ }
58
+
59
+ /**
60
+ * 输出错误日志
61
+ * @param {string} message - 日志消息
62
+ * @param {...any} args - 额外参数
63
+ */
64
+ export function error(message, ...args) {
65
+ if (!DEBUG) return;
66
+ const timestamp = new Date().toISOString().split("T")[1].slice(0, 12);
67
+ console.error(`[ERROR ${timestamp}] ${message}`, ...args);
68
+ }
69
+
70
+ /**
71
+ * 性能追踪装饰器
72
+ * @param {string} label - 标签
73
+ * @param {Function} fn - 要执行的函数
74
+ * @returns {any} 函数执行结果
75
+ */
76
+ export async function trace(label, fn) {
77
+ time(label);
78
+ try {
79
+ const result = await fn();
80
+ timeEnd(label);
81
+ return result;
82
+ } catch (err) {
83
+ timeEnd(label);
84
+ throw err;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * 同步版本的性能追踪
90
+ * @param {string} label - 标签
91
+ * @param {Function} fn - 要执行的函数
92
+ * @returns {any} 函数执行结果
93
+ */
94
+ export function traceSync(label, fn) {
95
+ time(label);
96
+ try {
97
+ const result = fn();
98
+ timeEnd(label);
99
+ return result;
100
+ } catch (err) {
101
+ timeEnd(label);
102
+ throw err;
103
+ }
104
+ }
105
+
106
+ export default {
107
+ DEBUG,
108
+ time,
109
+ timeEnd,
110
+ debug,
111
+ warn,
112
+ error,
113
+ trace,
114
+ traceSync,
115
+ };