From d42664790ea47474382846672be5eb47e318ffdb Mon Sep 17 00:00:00 2001 From: yibo Date: Tue, 1 Sep 2026 17:16:36 +0800 Subject: [PATCH] fix(cli): lemon.js goal create/list/status 改走公司级 /api/company/:id/goals --- bin/lemon.js | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/bin/lemon.js b/bin/lemon.js index 64c850d..51bb410 100755 --- a/bin/lemon.js +++ b/bin/lemon.js @@ -98,10 +98,19 @@ async function run() { } else if (command === 'okr create' || command === 'goal create') { const { values } = parseArgs({ args: args.slice(2), options: { - title: { type: 'string' }, desc: { type: 'string' }, owner: { type: 'string' } + title: { type: 'string' }, desc: { type: 'string' }, owner: { type: 'string' }, + // 38 号文档 Phase 2 把 /api/okr 收紧成 requireAdmin,agent 跑 CLI 必 401; + // 公司级正确入口是 POST /api/company/:id/goals(requireAuthOrInternal)。--company + // 缺省回落到 LEMON_COMPANY(agent 子进程由公司心跳带下来时可直接省略)。 + company: { type: 'string' } }}); - const res = await request('POST', '/okr', { title: values.title, description: values.desc, owner: values.owner }); - console.log(JSON.stringify(res.data, null, 2)); + const cid = values.company || process.env.LEMON_COMPANY; + if (!cid) { + console.log('❌ goal create 需要公司级入口:请带 --company (或设 LEMON_COMPANY)。/api/okr 是 admin-only,agent 调必 401。'); + } else { + const res = await request('POST', `/company/${cid}/goals`, { title: values.title, description: values.desc, split: false, report_to: values.owner }); + console.log(JSON.stringify(res.data, null, 2)); + } } else if (command === 'okr add-node' || command === 'goal add-node') { const { values } = parseArgs({ args: args.slice(2), options: { @@ -124,13 +133,24 @@ async function run() { console.log(JSON.stringify(res.data, null, 2)); } else if (command === 'okr list' || command === 'goal list') { - const res = await request('GET', '/okr'); - console.log(JSON.stringify(res.data, null, 2)); + const { values } = parseArgs({ args: args.slice(2), options: { company: { type: 'string' } }}); + const cid = values.company || process.env.LEMON_COMPANY; + if (!cid) { + console.log('❌ goal list 请带 --company (或设 LEMON_COMPANY)。/api/okr 是 admin-only,agent 调必 401。'); + } else { + const res = await request('GET', `/company/${cid}/goals`); + console.log(JSON.stringify(res.data, null, 2)); + } } else if (command === 'okr status' || command === 'goal status') { - const { values } = parseArgs({ args: args.slice(2), options: { goal: { type: 'string' } }}); - const res = await request('GET', `/okr/${values.goal}/progress`); - console.log(JSON.stringify(res.data, null, 2)); + const { values } = parseArgs({ args: args.slice(2), options: { goal: { type: 'string' }, company: { type: 'string' } }}); + const cid = values.company || process.env.LEMON_COMPANY; + if (!cid) { + console.log('❌ goal status 请带 --company (或设 LEMON_COMPANY)。/api/okr 是 admin-only,agent 调必 401。'); + } else { + const res = await request('GET', `/company/${cid}/goals/${values.goal}`); + console.log(JSON.stringify(res.data, null, 2)); + } } else if (command === 'goal update') { const { values } = parseArgs({ args: args.slice(2), options: { -- libgit2 0.21.4