@agents-uni/zhenhuan 0.1.1 → 0.1.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/README.en.md CHANGED
@@ -86,7 +86,7 @@ npm install
86
86
  ### Start the server
87
87
 
88
88
  ```bash
89
- # Global install, then use directly
89
+ # Global install, then use from any directory
90
90
  npm install -g @agents-uni/zhenhuan
91
91
  zhenhuan serve
92
92
 
@@ -95,8 +95,13 @@ npm start
95
95
 
96
96
  # Or with npx (no global install needed)
97
97
  npx @agents-uni/zhenhuan serve
98
+
99
+ # Use a custom spec file
100
+ zhenhuan serve --spec /path/to/my-universe.yaml
98
101
  ```
99
102
 
103
+ > 💡 **Path resolution**: `zhenhuan` first looks for `universe.yaml` in the current directory. If not found, it automatically uses the built-in default palace configuration. You can also specify a custom spec file with `--spec`.
104
+
100
105
  On startup, it prints the access URLs:
101
106
 
102
107
  ```
package/README.md CHANGED
@@ -86,7 +86,7 @@ npm install
86
86
  ### 启动服务器
87
87
 
88
88
  ```bash
89
- # 全局安装后直接使用
89
+ # 全局安装后,在任意目录直接使用
90
90
  npm install -g @agents-uni/zhenhuan
91
91
  zhenhuan serve
92
92
 
@@ -95,8 +95,13 @@ npm start
95
95
 
96
96
  # 或用 npx(无需全局安装)
97
97
  npx @agents-uni/zhenhuan serve
98
+
99
+ # 使用自定义规范文件
100
+ zhenhuan serve --spec /path/to/my-universe.yaml
98
101
  ```
99
102
 
103
+ > 💡 **路径解析逻辑**:`zhenhuan` 会优先查找当前目录下的 `universe.yaml`,找不到时自动使用包自带的默认甄嬛后宫配置。你也可以通过 `--spec` 显式指定规范文件路径。
104
+
100
105
  启动后会打印访问链接:
101
106
 
102
107
  ```
package/dist/cli/index.js CHANGED
@@ -4,8 +4,37 @@
4
4
  */
5
5
  import { Command } from 'commander';
6
6
  import chalk from 'chalk';
7
+ import { resolve, dirname, join } from 'node:path';
8
+ import { existsSync } from 'node:fs';
9
+ import { fileURLToPath } from 'node:url';
7
10
  import { PalaceOrchestrator } from '../orchestrator/index.js';
8
11
  import { startServer } from '../server/index.js';
12
+ /**
13
+ * 解析 universe.yaml 路径:
14
+ * 1. 用户显式指定 --spec → 直接用
15
+ * 2. CWD 下存在 universe.yaml → 用它
16
+ * 3. fallback 到包自带的 universe.yaml(全局安装场景)
17
+ */
18
+ function resolveSpec(specOpt) {
19
+ // 用户显式传了绝对路径或非默认值
20
+ if (specOpt !== 'universe.yaml') {
21
+ return resolve(specOpt);
22
+ }
23
+ // CWD 下有 universe.yaml,优先使用
24
+ const cwdSpec = resolve('universe.yaml');
25
+ if (existsSync(cwdSpec)) {
26
+ return cwdSpec;
27
+ }
28
+ // fallback: 包目录下的 universe.yaml(npm 全局安装场景)
29
+ const __dirname = dirname(fileURLToPath(import.meta.url));
30
+ const bundledSpec = join(__dirname, '..', '..', 'universe.yaml');
31
+ if (existsSync(bundledSpec)) {
32
+ console.log(chalk.gray(` ℹ 使用内置 universe.yaml (${bundledSpec})`));
33
+ return bundledSpec;
34
+ }
35
+ // 都找不到,返回原始路径(让后续报一个清晰的错误)
36
+ return cwdSpec;
37
+ }
9
38
  const program = new Command();
10
39
  program
11
40
  .name('zhenhuan')
@@ -18,11 +47,10 @@ program
18
47
  .option('-p, --port <port>', '端口号', '8089')
19
48
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
20
49
  .action(async (opts) => {
50
+ const specPath = resolveSpec(opts.spec);
21
51
  // Auto-register in uni-registry on serve
22
52
  try {
23
- const { resolve } = await import('node:path');
24
53
  const { registerUni, parseSpecFile } = await import('@agents-uni/core');
25
- const specPath = resolve(opts.spec);
26
54
  const config = parseSpecFile(specPath);
27
55
  registerUni(config, specPath);
28
56
  console.log(chalk.gray(` ✓ 已注册到 uni-registry`));
@@ -32,7 +60,7 @@ program
32
60
  }
33
61
  await startServer({
34
62
  port: parseInt(opts.port, 10),
35
- specPath: opts.spec,
63
+ specPath,
36
64
  });
37
65
  });
38
66
  // ─── status ─────────────────────────────────
@@ -41,7 +69,7 @@ program
41
69
  .description('查看后宫状态')
42
70
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
43
71
  .action(async (opts) => {
44
- const orchestrator = await PalaceOrchestrator.fromSpec(opts.spec);
72
+ const orchestrator = await PalaceOrchestrator.fromSpec(resolveSpec(opts.spec));
45
73
  const state = orchestrator.getState();
46
74
  console.log(chalk.yellow('\n═══ 后宫品级表 ═══\n'));
47
75
  // Sort by rank level descending
@@ -76,7 +104,7 @@ program
76
104
  .description('查看 ELO 排行榜')
77
105
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
78
106
  .action(async (opts) => {
79
- const orchestrator = await PalaceOrchestrator.fromSpec(opts.spec);
107
+ const orchestrator = await PalaceOrchestrator.fromSpec(resolveSpec(opts.spec));
80
108
  const board = orchestrator.getLeaderboard();
81
109
  console.log(chalk.yellow('\n═══ ELO 排行榜 ═══\n'));
82
110
  console.log(` ${chalk.gray('排名')} ${chalk.gray('ID'.padEnd(16))} ` +
@@ -102,7 +130,7 @@ program
102
130
  .description('召开朝会')
103
131
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
104
132
  .action(async (opts) => {
105
- const orchestrator = await PalaceOrchestrator.fromSpec(opts.spec);
133
+ const orchestrator = await PalaceOrchestrator.fromSpec(resolveSpec(opts.spec));
106
134
  console.log(chalk.yellow('\n═══ 朝会开始 ═══\n'));
107
135
  await orchestrator.runCourtAssembly();
108
136
  const state = orchestrator.getState();
@@ -123,7 +151,7 @@ program
123
151
  .option('--openclaw-dir <dir>', 'OpenClaw 目录', '')
124
152
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
125
153
  .action(async (opts) => {
126
- const orchestrator = await PalaceOrchestrator.fromSpec(opts.spec);
154
+ const orchestrator = await PalaceOrchestrator.fromSpec(resolveSpec(opts.spec));
127
155
  const agentDef = {
128
156
  id: opts.id,
129
157
  name: opts.name,
@@ -175,7 +203,7 @@ program
175
203
  .option('-s, --spec <path>', '规范文件路径', 'universe.yaml')
176
204
  .option('--agents <ids>', '参赛 Agent ID (逗号分隔,默认全部嫔妃)', '')
177
205
  .action(async (opts) => {
178
- const orchestrator = await PalaceOrchestrator.fromSpec(opts.spec);
206
+ const orchestrator = await PalaceOrchestrator.fromSpec(resolveSpec(opts.spec));
179
207
  // Determine participants: all agents by default (emperor is the user, not an agent)
180
208
  let participants;
181
209
  if (opts.agents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agents-uni/zhenhuan",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Zhen Huan palace drama themed agent competition system built on @agents-uni/core",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",