coze_lab 0.1.7 → 0.1.8

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.js +23 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4156,11 +4156,12 @@ function parseArgs() {
4156
4156
  const VALID_AGENTS = ['claude-code', 'codex', 'openclaw'];
4157
4157
 
4158
4158
  // resolveAgent 读 ~/.coze/agents/<agentId>/config.json,返回 { framework, workspace, agentId, root }。
4159
- // 目录或 config 不存在、framework 非法时直接报错退出。
4160
- function resolveAgent(agentId) {
4159
+ // soft=true 时,config 不存在 / 解析失败 / framework 非法均返回 null(不退出),供云端回退到显式 --agent。
4160
+ function resolveAgent(agentId, soft) {
4161
4161
  const root = path.join(os.homedir(), '.coze', 'agents', agentId);
4162
4162
  const configPath = path.join(root, 'config.json');
4163
4163
  if (!fs.existsSync(configPath)) {
4164
+ if (soft) return null;
4164
4165
  errorBox([
4165
4166
  `ERROR: agent "${agentId}" 不存在`,
4166
4167
  '',
@@ -4172,10 +4173,12 @@ function resolveAgent(agentId) {
4172
4173
  try {
4173
4174
  cfg = JSON.parse(fs.readFileSync(configPath, 'utf8'));
4174
4175
  } catch (e) {
4176
+ if (soft) return null;
4175
4177
  errorBox([`ERROR: 解析 ${configPath} 失败`, '', e.message]);
4176
4178
  }
4177
4179
  const framework = cfg.framework;
4178
4180
  if (!VALID_AGENTS.includes(framework)) {
4181
+ if (soft) return null;
4179
4182
  errorBox([
4180
4183
  `ERROR: agent "${agentId}" 的 framework="${framework}" 不受支持`,
4181
4184
  '',
@@ -4192,21 +4195,33 @@ function validateArgs(args) {
4192
4195
  if (args['refresh']) return { refresh: true };
4193
4196
  if (args['verify']) return { verify: true, pairCode: args['pair-code'] };
4194
4197
 
4195
- // --cloud + --agent-id:云端 sandbox 没有本地 coze-bridge 的 ~/.coze/agents/<id>/config.json
4196
- // framework 必须由命令行 --agent 显式传(前端拼命令时已知 agent.framework)。不读本地 config。
4198
+ // --cloud + --agent-id:优先读云端 ~/.coze/agents/<id>/config.json 拿 framework + workspace
4199
+ // (云端 config.json 稳定存在);读不到再回退到命令行显式 --agent(workspace main 推断)。
4197
4200
  if (args['cloud'] && args['agent-id']) {
4201
+ const resolved = resolveAgent(args['agent-id'], true /* soft */);
4202
+ if (resolved) {
4203
+ return {
4204
+ agent: resolved.framework,
4205
+ agentId: resolved.agentId,
4206
+ workspace: resolved.workspace,
4207
+ agentRoot: resolved.root,
4208
+ 'codex-home': args['codex-home'],
4209
+ pairCode: args['pair-code'],
4210
+ cloud: true,
4211
+ };
4212
+ }
4213
+ // config.json 缺失:回退到显式 --agent
4198
4214
  if (!args['agent'] || !VALID_AGENTS.includes(args['agent'])) {
4199
4215
  errorBox([
4200
- 'ERROR: --cloud --agent-id=<id> 必须同时显式指定 --agent=<type>',
4216
+ `ERROR: 未找到 agent "${args['agent-id']}" config.json,且未显式指定 --agent`,
4201
4217
  '',
4202
- '云端 sandbox 无本地 config.json,无法自动推断 framework',
4203
- `请拼成:npx coze_lab --cloud --agent-id=${args['agent-id']} --agent=claude-code|codex|openclaw`,
4218
+ '请确认 agentId 正确,或显式拼上 framework',
4219
+ ` npx coze_lab --cloud --agent-id=${args['agent-id']} --agent=claude-code|codex|openclaw`,
4204
4220
  ]);
4205
4221
  }
4206
4222
  return {
4207
4223
  agent: args['agent'],
4208
4224
  agentId: args['agent-id'],
4209
- // 云端 claude-code 配置写进 agent workspace,缺省按约定路径推断(见 main)。
4210
4225
  workspace: args['workspace'] || '',
4211
4226
  'codex-home': args['codex-home'],
4212
4227
  pairCode: args['pair-code'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coze_lab",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Configure local AI agents (Claude Code, Codex, OpenClaw) to report traces to CozeLoop",
5
5
  "keywords": [
6
6
  "cozeloop",