@keyou007/agent-bot 0.1.2 → 0.1.4

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 (91) hide show
  1. package/.env.example +3 -1
  2. package/CHANGELOG.md +15 -0
  3. package/README.md +23 -8
  4. package/README.zh.md +23 -8
  5. package/config.example.yaml +1 -0
  6. package/dist/cli/FeishuAppConfiguration.js +10 -10
  7. package/dist/cli/FeishuAppConfiguration.js.map +1 -1
  8. package/dist/cli/FeishuAppRegistration.js +21 -11
  9. package/dist/cli/FeishuAppRegistration.js.map +1 -1
  10. package/dist/cli/Initializer.js +14 -8
  11. package/dist/cli/Initializer.js.map +1 -1
  12. package/dist/cli/LocalControlClient.js +2 -2
  13. package/dist/cli/LocalControlClient.js.map +1 -1
  14. package/dist/cli/LocalControlServer.js +1 -1
  15. package/dist/cli/LocalControlServer.js.map +1 -1
  16. package/dist/cli/ServerStarter.js +69 -0
  17. package/dist/cli/ServerStarter.js.map +1 -0
  18. package/dist/cli/SkillRegistry.js +4 -4
  19. package/dist/cli/SkillRegistry.js.map +1 -1
  20. package/dist/cli/help.js +5 -56
  21. package/dist/cli/help.js.map +1 -1
  22. package/dist/cli/packageVersion.js +1 -1
  23. package/dist/cli/packageVersion.js.map +1 -1
  24. package/dist/cli/profile.js +40 -0
  25. package/dist/cli/profile.js.map +1 -0
  26. package/dist/cli/serverStatus.js +37 -0
  27. package/dist/cli/serverStatus.js.map +1 -0
  28. package/dist/cli/taskChatRoute.js +2 -2
  29. package/dist/cli/taskChatRoute.js.map +1 -1
  30. package/dist/cli.js +148 -168
  31. package/dist/cli.js.map +1 -1
  32. package/dist/config/loadConfig.js +7 -2
  33. package/dist/config/loadConfig.js.map +1 -1
  34. package/dist/config/paths.js +1 -0
  35. package/dist/config/paths.js.map +1 -1
  36. package/dist/config/schema.js +1 -0
  37. package/dist/config/schema.js.map +1 -1
  38. package/dist/feishu/CardRenderer.js +21 -3
  39. package/dist/feishu/CardRenderer.js.map +1 -1
  40. package/dist/feishu/FeishuConnector.js +7 -76
  41. package/dist/feishu/FeishuConnector.js.map +1 -1
  42. package/dist/feishu/transport.js +1 -1
  43. package/dist/feishu/transport.js.map +1 -1
  44. package/dist/index.js +18 -9
  45. package/dist/index.js.map +1 -1
  46. package/dist/proxy/ProxySessionController.js +28 -13
  47. package/dist/proxy/ProxySessionController.js.map +1 -1
  48. package/dist/startup/StartupNotifier.js +13 -2
  49. package/dist/startup/StartupNotifier.js.map +1 -1
  50. package/dist/startup/startFeishu.js +1 -1
  51. package/dist/startup/startFeishu.js.map +1 -1
  52. package/dist/supervision/SafeRestartNotifier.js +23 -7
  53. package/dist/supervision/SafeRestartNotifier.js.map +1 -1
  54. package/dist/supervision/SafeRestartScheduler.js +20 -2
  55. package/dist/supervision/SafeRestartScheduler.js.map +1 -1
  56. package/dist/supervision/SupervisorDiagnostics.js +209 -0
  57. package/dist/supervision/SupervisorDiagnostics.js.map +1 -0
  58. package/dist/supervisor.js +47 -12
  59. package/dist/supervisor.js.map +1 -1
  60. package/docs/technical-reference.md +25 -5
  61. package/docs/technical-reference.zh.md +25 -5
  62. package/npm-shrinkwrap.json +2 -2
  63. package/package.json +1 -1
  64. package/skills/agent-bot/SKILL.md +24 -4
  65. package/src/cli/FeishuAppConfiguration.ts +10 -10
  66. package/src/cli/FeishuAppRegistration.ts +23 -10
  67. package/src/cli/Initializer.ts +14 -7
  68. package/src/cli/LocalControlClient.ts +2 -2
  69. package/src/cli/LocalControlServer.ts +1 -1
  70. package/src/cli/ServerStarter.ts +106 -0
  71. package/src/cli/SkillRegistry.ts +4 -4
  72. package/src/cli/help.ts +5 -65
  73. package/src/cli/packageVersion.ts +1 -1
  74. package/src/cli/profile.ts +59 -0
  75. package/src/cli/serverStatus.ts +39 -0
  76. package/src/cli/taskChatRoute.ts +2 -2
  77. package/src/cli.ts +160 -167
  78. package/src/config/loadConfig.ts +12 -2
  79. package/src/config/paths.ts +1 -0
  80. package/src/config/schema.ts +1 -0
  81. package/src/feishu/CardRenderer.ts +25 -3
  82. package/src/feishu/FeishuConnector.ts +6 -87
  83. package/src/feishu/transport.ts +1 -1
  84. package/src/index.ts +22 -9
  85. package/src/proxy/ProxySessionController.ts +28 -13
  86. package/src/startup/StartupNotifier.ts +21 -4
  87. package/src/startup/startFeishu.ts +1 -1
  88. package/src/supervision/SafeRestartNotifier.ts +22 -7
  89. package/src/supervision/SafeRestartScheduler.ts +27 -3
  90. package/src/supervision/SupervisorDiagnostics.ts +268 -0
  91. package/src/supervisor.ts +46 -11
package/src/cli/help.ts CHANGED
@@ -1,61 +1,4 @@
1
- export type CliLanguage = "en" | "zh";
2
-
3
- export function resolveCliLanguage(
4
- env: NodeJS.ProcessEnv = process.env,
5
- systemLocale = Intl.DateTimeFormat().resolvedOptions().locale,
6
- ): CliLanguage {
7
- const configuredLocale = [
8
- env.LC_ALL,
9
- env.LC_MESSAGES,
10
- env.LANGUAGE,
11
- env.LANG,
12
- ].find((value) => value?.trim());
13
- return isChineseLocale(configuredLocale ?? systemLocale) ? "zh" : "en";
14
- }
15
-
16
- export function renderCliHelp(version: string, language = resolveCliLanguage()): string {
17
- return language === "zh" ? renderChineseHelp(version) : renderEnglishHelp(version);
18
- }
19
-
20
- function renderChineseHelp(version: string): string {
21
- return `Agent Bot ${version}
22
- 通过飞书/Lark 使用本机 Codex 与 ACP Agent。
23
-
24
- 用法:
25
- agent-bot [选项] <命令>
26
-
27
- 常用命令:
28
- init 初始化配置、数据目录和飞书应用
29
- console 打开本地 Console
30
- server start 在后台启动 Agent Bot
31
- server status 查看服务和安全重启状态
32
- server restart 安排安全重启
33
- server stop 停止 Agent Bot
34
- task list 列出任务
35
- task status <task> 查看任务状态
36
- task chat <task> 查看任务绑定的飞书会话
37
- task prompt <task> <prompt> 向指定任务发送 Prompt
38
- task stop <task> 停止指定任务
39
- task title <task> <title> 修改任务标题
40
- skills status 查看内置 Skill 状态
41
- skills install 安装内置 Skill
42
-
43
- 选项:
44
- --config <path> 使用指定配置文件
45
- --json 在支持的命令中输出 JSON
46
- -h, --help 显示帮助
47
- -v, --version 显示版本
48
-
49
- 示例:
50
- agent-bot init
51
- agent-bot server start
52
- agent-bot server status
53
- agent-bot task list
54
- agent-bot server restart --reason "升级 Agent Bot"
55
- `;
56
- }
57
-
58
- function renderEnglishHelp(version: string): string {
1
+ export function renderCliHelp(version: string): string {
59
2
  return `Agent Bot ${version}
60
3
  Use local Codex and ACP agents from Lark/Feishu.
61
4
 
@@ -63,10 +6,10 @@ Usage:
63
6
  agent-bot [options] <command>
64
7
 
65
8
  Common commands:
66
- init Initialize config, data directories, and the Lark app
9
+ init Initialize the Lark app and start the service
67
10
  console Open the local console
68
11
  server start Start Agent Bot in the background
69
- server status Show server and safe-restart status
12
+ server status Show the server, Lark App ID, and safe-restart status
70
13
  server restart Schedule a safe restart
71
14
  server stop Stop Agent Bot
72
15
  task list List tasks
@@ -79,6 +22,7 @@ Common commands:
79
22
  skills install Install the built-in Skill
80
23
 
81
24
  Options:
25
+ --profile <directory> Use an isolated profile directory
82
26
  --config <path> Use a specific config file
83
27
  --json Print JSON when supported
84
28
  -h, --help Show help
@@ -86,14 +30,10 @@ Options:
86
30
 
87
31
  Examples:
88
32
  agent-bot init
33
+ agent-bot --profile ~/.agent-bot-rescue init
89
34
  agent-bot server start
90
35
  agent-bot server status
91
36
  agent-bot task list
92
37
  agent-bot server restart --reason "Update Agent Bot"
93
38
  `;
94
39
  }
95
-
96
- function isChineseLocale(value: string): boolean {
97
- const locale = value.trim().split(":")[0]?.split(/[.@]/)[0]?.replaceAll("_", "-").toLowerCase();
98
- return locale === "zh" || Boolean(locale?.startsWith("zh-"));
99
- }
@@ -8,7 +8,7 @@ export function readPackageVersion(
8
8
  fs.readFileSync(fileURLToPath(packageJsonUrl), "utf8"),
9
9
  ) as { version?: unknown };
10
10
  if (typeof metadata.version !== "string" || !metadata.version.trim()) {
11
- throw new Error("package.json 中缺少有效的 version。");
11
+ throw new Error("package.json does not contain a valid version.");
12
12
  }
13
13
  return metadata.version;
14
14
  }
@@ -0,0 +1,59 @@
1
+ import path from "node:path";
2
+ import {
3
+ AGENT_BOT_EXPLICIT_PROFILE_ENV,
4
+ AGENT_BOT_HOME_ENV,
5
+ DEFAULT_CONFIG_FILE,
6
+ resolveUserPath,
7
+ } from "../config/paths.js";
8
+
9
+ export interface ParsedGlobalOptions {
10
+ args: string[];
11
+ configPath?: string;
12
+ profilePath?: string;
13
+ }
14
+
15
+ export interface AppliedProfile {
16
+ homePath: string;
17
+ configPath: string;
18
+ }
19
+
20
+ export function parseGlobalOptions(input: string[]): ParsedGlobalOptions {
21
+ const args = [...input];
22
+ const configPath = removeOption(args, "--config");
23
+ const profilePath = removeOption(args, "--profile");
24
+ if (configPath && profilePath) {
25
+ throw new Error("--profile and --config cannot be used together. A profile always uses config.yaml in its directory.");
26
+ }
27
+ return {
28
+ args,
29
+ ...(configPath ? { configPath } : {}),
30
+ ...(profilePath ? { profilePath } : {}),
31
+ };
32
+ }
33
+
34
+ export function applyExplicitProfile(
35
+ profilePath: string,
36
+ env: NodeJS.ProcessEnv = process.env,
37
+ baseDirectory = process.cwd(),
38
+ ): AppliedProfile {
39
+ const homePath = resolveUserPath(profilePath, baseDirectory);
40
+ const configPath = path.join(homePath, DEFAULT_CONFIG_FILE);
41
+ env[AGENT_BOT_HOME_ENV] = homePath;
42
+ env.AGENT_BOT_CONFIG = configPath;
43
+ env[AGENT_BOT_EXPLICIT_PROFILE_ENV] = "1";
44
+ delete env.FEISHU_APP_ID;
45
+ delete env.FEISHU_APP_SECRET;
46
+ delete env.FEISHU_USER_OPEN_ID;
47
+ return { homePath, configPath };
48
+ }
49
+
50
+ function removeOption(args: string[], option: string): string | undefined {
51
+ const indexes = args.flatMap((value, index) => value === option ? [index] : []);
52
+ if (indexes.length > 1) throw new Error(`${option} can only be specified once.`);
53
+ const index = indexes[0];
54
+ if (index === undefined) return undefined;
55
+ const value = args[index + 1];
56
+ if (!value || value.startsWith("--")) throw new Error(`${option} requires a directory or file path.`);
57
+ args.splice(index, 2);
58
+ return value;
59
+ }
@@ -0,0 +1,39 @@
1
+ export function withConfiguredFeishuAppId(
2
+ data: unknown,
3
+ configuredFeishuAppId?: string,
4
+ ): Record<string, unknown> {
5
+ const value = data && typeof data === "object"
6
+ ? data as Record<string, unknown>
7
+ : {};
8
+ if (Object.hasOwn(value, "feishuAppId")) return value;
9
+ return {
10
+ ...value,
11
+ feishuAppId: configuredFeishuAppId ?? null,
12
+ };
13
+ }
14
+
15
+ export function formatServerStatus(data: unknown): string {
16
+ const value = data && typeof data === "object" ? data as Record<string, unknown> : {};
17
+ const activity = value.activity && typeof value.activity === "object"
18
+ ? value.activity as Record<string, unknown>
19
+ : {};
20
+ const state = value.running === false
21
+ ? "not running"
22
+ : value.ready === false
23
+ ? "starting (connecting to Lark)"
24
+ : "running";
25
+ const safeRestart = value.safeRestartScheduled
26
+ ? `pending (${String(value.safeRestartReason ?? "no reason provided")})`
27
+ : "not scheduled";
28
+ return [
29
+ `Agent Bot server: ${state}`,
30
+ `Lark App ID: ${value.feishuAppId ?? "not configured"}`,
31
+ `PID: ${value.pid ?? "-"}`,
32
+ `Started at: ${value.startedAt ?? "-"}`,
33
+ `Supervisor: ${value.supervised ? "enabled" : "disabled"}`,
34
+ `Running tasks: ${activity.runningSessions ?? 0}`,
35
+ `Pending final deliveries: ${activity.pendingFinalDeliveries ?? 0}`,
36
+ `Safe restart: ${safeRestart}`,
37
+ "",
38
+ ].join("\n");
39
+ }
@@ -15,10 +15,10 @@ export function taskChatRoute(session: SessionRecord): TaskChatRoute {
15
15
  const contextKey = session.contextKey;
16
16
  const baseContextKey = baseChatContextKey(contextKey);
17
17
  if (!baseContextKey.startsWith(CHAT_CONTEXT_PREFIX)) {
18
- throw new Error(`任务没有绑定飞书会话:${session.remoteSessionId ?? session.acpSessionId ?? session.localSessionId}`);
18
+ throw new Error(`The task is not bound to a Lark chat: ${session.remoteSessionId ?? session.acpSessionId ?? session.localSessionId}`);
19
19
  }
20
20
  const chatId = baseContextKey.slice(CHAT_CONTEXT_PREFIX.length);
21
- if (!chatId) throw new Error(`任务的飞书会话 ID 无效:${contextKey}`);
21
+ if (!chatId) throw new Error(`The task has an invalid Lark chat ID: ${contextKey}`);
22
22
  const threadId = isThreadContextKey(contextKey)
23
23
  ? contextKey.slice(contextKey.indexOf(THREAD_CONTEXT_MARKER) + THREAD_CONTEXT_MARKER.length)
24
24
  : undefined;