coze_lab 0.1.6 → 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 +46 -4
  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,7 +4195,41 @@ 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
- // 优先 --agent-id:读 ~/.coze/agents/<id>/config.json framework 自动路由。
4198
+ // --cloud + --agent-id:优先读云端 ~/.coze/agents/<id>/config.json framework + workspace
4199
+ // (云端 config.json 稳定存在);读不到再回退到命令行显式 --agent(workspace 在 main 推断)。
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
4214
+ if (!args['agent'] || !VALID_AGENTS.includes(args['agent'])) {
4215
+ errorBox([
4216
+ `ERROR: 未找到 agent "${args['agent-id']}" 的 config.json,且未显式指定 --agent`,
4217
+ '',
4218
+ '请确认 agentId 正确,或显式拼上 framework:',
4219
+ ` npx coze_lab --cloud --agent-id=${args['agent-id']} --agent=claude-code|codex|openclaw`,
4220
+ ]);
4221
+ }
4222
+ return {
4223
+ agent: args['agent'],
4224
+ agentId: args['agent-id'],
4225
+ workspace: args['workspace'] || '',
4226
+ 'codex-home': args['codex-home'],
4227
+ pairCode: args['pair-code'],
4228
+ cloud: true,
4229
+ };
4230
+ }
4231
+
4232
+ // 本地 --agent-id:读 ~/.coze/agents/<id>/config.json 的 framework 自动路由。
4196
4233
  if (args['agent-id']) {
4197
4234
  const resolved = resolveAgent(args['agent-id']);
4198
4235
  return {
@@ -5123,7 +5160,12 @@ async function main() {
5123
5160
  // 云端模式:开启结构化输出 + errorBox 抛异常(而非 exit)。
5124
5161
  CLOUD_MODE = !!args.cloud;
5125
5162
  // per-agent 路由时 agent 的 workspace(claude-code 用它做配置根目录)。
5126
- const agentWorkspace = args.workspace || '';
5163
+ // per-agent 路由时 agent 的 workspace(claude-code 用它做配置根目录)。
5164
+ // 云端 claude-code 未显式传 workspace 时,按约定路径 ~/.coze/agents/<id>/workspace 推断。
5165
+ let agentWorkspace = args.workspace || '';
5166
+ if (args.cloud && args.agentId && agent === 'claude-code' && !agentWorkspace) {
5167
+ agentWorkspace = path.join(os.homedir(), '.coze', 'agents', args.agentId, 'workspace');
5168
+ }
5127
5169
  if (args.agentId) {
5128
5170
  info(`目标 agent: ${args.agentId} (framework=${agent}, workspace=${agentWorkspace || 'N/A'})`);
5129
5171
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coze_lab",
3
- "version": "0.1.6",
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",