Skip to content

Commit 43a32ff

Browse files
committed
fix(agents): support optional claude agents
1 parent 7d26164 commit 43a32ff

3 files changed

Lines changed: 55 additions & 9 deletions

File tree

‎app/service/agents.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,22 @@ class AgentsService extends Service {
292292

293293
const name = this.validateAgentName(manifest.name);
294294
const version = manifest.version ? this.validateAgentVersion(manifest.version) : '';
295-
const agents = Array.isArray(manifest.agents) ? manifest.agents : [];
296-
if (agents.length === 0) {
297-
this.ctx.throw(400, '.claude-plugin/plugin.json 必须声明 agents');
295+
296+
// agents 在 Claude Code 规范中为可选配置,支持单个路径字符串或路径数组
297+
let agents = [];
298+
if (typeof manifest.agents === 'string' && manifest.agents.trim()) {
299+
agents = [this.normalizeManifestPath(manifest.agents, 'agents')];
300+
} else if (Array.isArray(manifest.agents)) {
301+
agents = manifest.agents
302+
.map((item) => String(item || '').trim())
303+
.filter(Boolean)
304+
.map((item) => this.normalizeManifestPath(item, 'agents'));
298305
}
299306

300307
return {
301308
name,
302309
version,
303-
agents: agents.map((item) => this.normalizeManifestPath(item, 'agents')),
310+
agents,
304311
};
305312
}
306313

‎docs/docsify/zh-cn/guide/agent-market.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Doraemon 采用 GitOps 模式管理 Agent 插件,实现代码集中在 GitLab
207207
- 检查根目录下 `.codex-plugin/plugin.json` 与 `.claude-plugin/plugin.json` 是否齐全。
208208
- 校验 Manifest 中的 `name` 必须与 GitLab 仓库名(去除 `.git` 后缀)完全一致。
209209
- 校验两个 Manifest 中的 `version` 核心版本号必须完全一致。
210-
- 校验 `skills` 声明的目录及 Claude `agents` 引用的角色文件真实存在。
210+
- 校验 `skills` 声明的目录是否存在(若声明了 Claude `agents` 路径则校验其路径格式合法性)。
211211
4. **精确版本追踪(Content Hash)**:
212212
- 执行 `git rev-parse HEAD` 获取当前分支最新提交的 Commit SHA 作为 `content_hash`。
213213
- 数据库分别维护:
@@ -361,7 +361,7 @@ bugfix-agent
361361
```
362362

363363
- `name`:必须与 `.codex-plugin/plugin.json` 的 `name` 严格保持一致。
364-
- `agents`:必须声明角色定义文件相对路径列表,引用的文件在仓库内必须真实存在。
364+
- `agents`:可选。若包含 Claude Code 角色定义,可声明角色文件或目录的相对路径(支持字符串如 `"./agents/claude"` 或文件列表数组如 `["./agents/claude/bugfix-worker.md"]`;若无需自定义 subagents 可省略或留空)。
365365

366366
## 服务端配置说明
367367

‎test/agent-plugin-contract.test.js‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,50 @@ test('validateCodexManifest 支持最多 1024 字符的多行代码块 defaultPr
104104
);
105105
});
106106

107-
test('validateClaudeManifest 校验 agents 配置有效性', () => {
107+
test('validateClaudeManifest 支持 agents 为可选配置,并兼容字符串或数组格式', () => {
108108
const service = createService();
109+
110+
// 1. 省略 agents 或传空数组正常通过
111+
assert.deepEqual(service.validateClaudeManifest({ name: 'bugfix-agent' }).agents, []);
112+
assert.deepEqual(
113+
service.validateClaudeManifest({ name: 'bugfix-agent', agents: [] }).agents,
114+
[]
115+
);
116+
assert.deepEqual(
117+
service.validateClaudeManifest({ name: 'bugfix-agent', agents: '' }).agents,
118+
[]
119+
);
120+
121+
// 2. 支持单个字符串路径
122+
assert.deepEqual(
123+
service.validateClaudeManifest({
124+
name: 'bugfix-agent',
125+
agents: './agents/claude',
126+
}).agents,
127+
['agents/claude']
128+
);
129+
130+
// 3. 支持数组格式路径列表
131+
assert.deepEqual(
132+
service.validateClaudeManifest({
133+
name: 'bugfix-agent',
134+
agents: ['./agents/claude/worker.md', './agents/claude/reviewer.md'],
135+
}).agents,
136+
['agents/claude/worker.md', 'agents/claude/reviewer.md']
137+
);
138+
139+
// 4. 非法相对路径(非 ./ 开头)仍应拦截
140+
assert.throws(
141+
() => service.validateClaudeManifest({ name: 'bugfix-agent', agents: 'invalid/path' }),
142+
/agents 必须是 \.\/ 开头的相对路径/
143+
);
109144
assert.throws(
110-
() => service.validateClaudeManifest({ name: 'bugfix-agent', agents: [] }),
111-
/\.claude-plugin\/plugin\.json 必须声明 agents/
145+
() =>
146+
service.validateClaudeManifest({
147+
name: 'bugfix-agent',
148+
agents: ['invalid/path'],
149+
}),
150+
/agents 必须是 \.\/ 开头的相对路径/
112151
);
113152
});
114153

0 commit comments

Comments
 (0)