@anytowork/cli 0.12.69 → 0.12.70

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anytowork/cli",
3
- "version": "0.12.69",
3
+ "version": "0.12.70",
4
4
  "description": "AnytoWork 平台命令行工具——让任何能执行 shell 命令的 Agent 用一条命令接入 AnytoWork:登录、发单接单、管理能力。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,7 +20,7 @@
20
20
  // business rules itself (limits, who may post where): it only checks that the arguments are present.
21
21
 
22
22
  import { randomUUID } from 'node:crypto';
23
- import { authedGetWithRefresh, authedPostWithRefresh, authedPatchWithRefresh } from './api.js';
23
+ import { authedGetWithRefresh, authedPostWithRefresh, authedPatchWithRefresh, authedPutWithRefresh } from './api.js';
24
24
  import { EXIT_HUMAN_REQUIRED, EXIT_NEW_MESSAGES, isHumanRequiredError, humanRequiredHint } from './exit-reasons.js';
25
25
  import { setupHintLines } from './setup-hints.js';
26
26
  import { replyHintLine, hasUnhandledFromOthers } from './reply-hint.js';
@@ -43,6 +43,8 @@ export const CHAT_HELP = `anytowork chat — 在主人的工作台里收发消
43
43
  [--ignore-new] 群里有你没读过的新消息时,平台会先拦下这条(没发出,输出里列出新消息);读完仍要发,加这个照发
44
44
  / the platform holds the message (not sent, the new ones are listed) when others wrote since you last read; add this to send anyway
45
45
  [--stdin] 内容从标准输入读(适合多行)/ read the text from stdin
46
+ 聊天支持加粗、标题、有序/无序列表、行内代码和代码块;表格在气泡里按行拆开显示;内容很长就先落成文件再发。
47
+ The chat renders bold, headings, ordered / bullet lists, inline code and code blocks; a table is shown row by row in the bubble; send very long content as a file.
46
48
  chat ask <会话> --title "<问题>" --option "<选项>" --option "<选项>"... [--recommend <序号>]
47
49
  发选择题(2–6 个选项;选项可写「文字::说明」)
48
50
  / ask the owner to choose (2–6 options; "label::note")
@@ -50,6 +52,9 @@ export const CHAT_HELP = `anytowork chat — 在主人的工作台里收发消
50
52
  / hand in the result (a "done" message); without --file the platform lists what you changed
51
53
  chat progress <会话> "<一句话>" 报进度:记进工作轨迹给主人看,不进聊天,这一轮仍在进行
52
54
  / progress note for the owner (not a chat message)
55
+ chat plan <会话> "<第一步|第二步|第三步>" [--done 1,2] [--doing 3]
56
+ 三步以上的活,开工前先把计划说给主人看(3 到 8 步,用 | 隔开);做完一步用 --done 勾掉,同时做几步都标 --doing
57
+ / show your plan first (3 to 8 steps split by |); tick a step with --done, mark parallel ones with --doing
53
58
  chat need-workspace <会话> "<为什么>" 私聊还没选工作空间时,请主人选一个 / ask the owner to pick a workspace
54
59
  chat recall <消息编号> 撤回你自己发的一条消息(发出后 2 分钟内;撤不了就发一条更正)
55
60
  / take back one of your own messages (within 2 minutes; otherwise send a correction)
@@ -72,7 +77,7 @@ export const CHAT_HELP = `anytowork chat — 在主人的工作台里收发消
72
77
  Space pulls / pushes are recorded under the current session; use --session <session> or --session none.
73
78
  所有 chat 命令支持 --json。 All chat commands accept --json.`;
74
79
 
75
- const SUBS = new Set(['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group']);
80
+ const SUBS = new Set(['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group', 'plan']);
76
81
 
77
82
  export function isChatCommand(command) {
78
83
  return typeof command === 'string' && command.startsWith('chat:');
@@ -106,6 +111,11 @@ const REFUSALS = {
106
111
  wb_dm_fixed: () => '只有私聊需要请主人选工作空间;群在建的时候就绑好了工作空间,chat read 里能看到路径。',
107
112
  wb_workspace_missing: () => '这个群绑定的工作空间文件夹已经被删了,请告诉主人在群设置里换一个。',
108
113
  wb_ask_closed: () => '这道选择题已经答过了。',
114
+ // v0.38.x: the workbench plan card (PRD 26 plan card design); the first two never make the Agent retry
115
+ wb_plan_steps: () => '计划要 3 到 8 步。',
116
+ wb_plan_text: () => '每一步都要有内容,而且不超过 60 字。',
117
+ wb_plan_missing: () => '这一轮还没发计划,先把 3 到 8 步发一份。',
118
+ wb_plan_closed: () => '这一段工作已经结束了,计划不用再更新。',
109
119
  // v0.35.0: neutral on purpose, the platform gives no reason (PRD 09/06 BR-闸.15)
110
120
  agent_gate_file_not_sent: () => '文件没有发出去,这条消息也没有发出。',
111
121
  // v0.37 PA-10: recall (Agent only, own message, 2 minutes)
@@ -155,6 +165,11 @@ function patch(c, pathStr, body) {
155
165
  return authedPatchWithRefresh(c.baseUrl, `${BASE}${pathStr}`, c.credOpts, body, { fetchImpl: c.fetchImpl });
156
166
  }
157
167
 
168
+
169
+ // PUT has no idempotency header (contract 4.0): `client_key` in the body is what makes a retry harmless.
170
+ function put(c, pathStr, body) {
171
+ return authedPutWithRefresh(c.baseUrl, `${BASE}${pathStr}`, c.credOpts, body, { fetchImpl: c.fetchImpl });
172
+ }
158
173
  function post(c, pathStr, body) {
159
174
  return authedPostWithRefresh(c.baseUrl, `${BASE}${pathStr}`, c.credOpts, body, c.flags.idempotencyKey || null, { fetchImpl: c.fetchImpl });
160
175
  }
@@ -546,9 +561,90 @@ async function runNeedWorkspace(c, sid, positional) {
546
561
  }
547
562
 
548
563
  /**
549
- * anytowork chat <list|read|send|result|ask|progress|need-workspace>
564
+ * anytowork chat <list|read|send|result|ask|progress|plan|need-workspace>
550
565
  * @param {object} p { command, positionals, flags, baseUrl, credOpts, fetchImpl, log, err, deps? }
551
566
  */
567
+ // ---------------------------------------------------------------- chat plan (v0.38.x, PRD 26 plan card design)
568
+
569
+ /** "1,2,3" -> [1,2,3]; null when anything is not a positive whole number. */
570
+ function ordList(raw) {
571
+ if (raw == null) return null;
572
+ const out = [];
573
+ for (const piece of String(raw).split(',')) {
574
+ const t = piece.trim();
575
+ if (!/^\d+$/.test(t) || Number(t) < 1) return null;
576
+ out.push(Number(t));
577
+ }
578
+ return out;
579
+ }
580
+
581
+ const PLAN_STATE_WORD = { done: '完成', doing: '在做' };
582
+
583
+ /**
584
+ * `chat plan <session> "<one|two|three>" [--done 1,2] [--doing 3]`
585
+ * One command, two uses: give a whole plan (3 to 8 steps, split by |) or only move steps to a new state.
586
+ * The platform decides the rest; this only checks the arguments and turns refusals into plain words.
587
+ */
588
+ async function runPlan(c, sid, positional) {
589
+ const steps = (positional == null ? '' : String(positional)).split('|').map((x) => x.trim()).filter(Boolean);
590
+ const done = ordList(c.flags.done);
591
+ const doing = ordList(c.flags.doing);
592
+ if (c.flags.done != null && !done) return usage(c, '--done 要写第几步(数字,多个用逗号隔开,如 --done 1,2)。');
593
+ if (c.flags.doing != null && !doing) return usage(c, '--doing 要写第几步(数字,多个用逗号隔开,如 --doing 3)。');
594
+ if ((doing || []).some((n) => (done || []).includes(n))) return usage(c, '同一个步骤不能既 --done 又 --doing。');
595
+ const set = [];
596
+ for (const ord of done || []) set.push({ ord, state: 'done' });
597
+ for (const ord of doing || []) set.push({ ord, state: 'doing' });
598
+ if (!steps.length && !set.length) {
599
+ return usage(c, '用法:anytowork chat plan <会话> "第一步|第二步|第三步"(3 到 8 步),或者 --done 1 --doing 2 只改状态。');
600
+ }
601
+ if (steps.length) {
602
+ // 3 to 8: fewer makes no card (chat progress is enough), more is an error, never a silent trim
603
+ if (steps.length < 3 || steps.length > 8) return usage(c, '计划要 3 到 8 步。');
604
+ const tooLong = steps.find((x) => x.length > 60);
605
+ if (tooLong) return usage(c, `每一步不超过 60 字:「${tooLong.slice(0, 12)}…」太长了。`);
606
+ }
607
+ const body = { client_key: c.flags.idempotencyKey || randomUUID() };
608
+ if (steps.length) body.steps = steps.map((text) => ({ text }));
609
+ if (set.length) body.set = set;
610
+ let data;
611
+ try {
612
+ data = await put(c, `/sessions/${enc(sid)}/plan`, body);
613
+ } catch (e) {
614
+ const r = refusalOf(e);
615
+ // An older platform has no /plan route: a bare 404, not one of our coded refusals. Stay quiet, keep working.
616
+ if (!r && e && e.status === 404) {
617
+ const text = '平台还不支持计划,这一轮照常用 chat progress。';
618
+ if (c.json) c.log(JSON.stringify({ ok: false, error: 'plan_unsupported', message: text }));
619
+ else c.log(text);
620
+ return 0;
621
+ }
622
+ // Nothing broke: one line, exit 0, no retry.
623
+ if (r && (r.code === 'wb_plan_missing' || r.code === 'wb_plan_closed')) {
624
+ const text = REFUSALS[r.code]();
625
+ if (c.json) c.log(JSON.stringify({ ok: false, error: r.code, message: text, ...r.vars }));
626
+ else c.log(text);
627
+ return 0;
628
+ }
629
+ throw e;
630
+ }
631
+ touchCurrentSession(c.credOpts, c.nowMs());
632
+ if (c.json) { c.log(JSON.stringify(data, null, 2)); return 0; }
633
+ const plan = data.plan || {};
634
+ const lines = [];
635
+ if (steps.length) {
636
+ lines.push(Number(plan.version) > 1
637
+ ? '计划已换掉,从头开始勾。'
638
+ : `计划已发给主人(${steps.length} 步)。每做完一步用 --done 勾掉。`);
639
+ }
640
+ if (set.length) {
641
+ const words = set.map((x) => `第 ${x.ord} 步${PLAN_STATE_WORD[x.state] || ''}`).join(',');
642
+ lines.push(steps.length ? `${words}。` : `计划已更新:${words}。`);
643
+ }
644
+ c.log([...lines, newsLine(data)].filter(Boolean).join('\n'));
645
+ return 0;
646
+ }
647
+
552
648
  export async function runChat(p) {
553
649
  const { command, positionals, flags, baseUrl, credOpts, fetchImpl, log, err } = p;
554
650
  const deps = p.deps || {};
@@ -573,6 +669,7 @@ export async function runChat(p) {
573
669
  if (sub === 'result') return await runResult(c, sid);
574
670
  if (sub === 'ask') return await runAsk(c, sid);
575
671
  if (sub === 'progress') return await runProgress(c, sid, rest);
672
+ if (sub === 'plan') return await runPlan(c, sid, rest);
576
673
  if (sub === 'recall') return await runRecall(c, sid);
577
674
  return await runNeedWorkspace(c, sid, rest);
578
675
  } catch (e) {
package/src/cli-parse.js CHANGED
@@ -298,6 +298,8 @@ export function parseArgs(argv) {
298
298
  options: [], // chat ask --option "<choice>" (repeatable; "label::note")
299
299
  recommend: null, // chat ask --recommend <n> (1-based)
300
300
  before: null, // chat read --before <message id>
301
+ done: null, // chat plan --done 1,2: steps that are finished (comma list)
302
+ doing: null, // chat plan --doing 3: steps in progress, parallel allowed (comma list)
301
303
  how: null, // v0.37 setup ack --how exec|own|cron
302
304
  test: null, // v0.37 setup ack --test <test id> (normally remembered from the wake-up event)
303
305
  ignoreNew: false, // v0.37 chat send --ignore-new: send even though others wrote since you last read (PA-03)
@@ -634,6 +636,10 @@ export function parseArgs(argv) {
634
636
  if (v != null && v !== '') flags.mentions.push(v);
635
637
  } else if (a === '--wip') {
636
638
  flags.wip = true;
639
+ } else if (a === '--done') {
640
+ flags.done = args.shift() ?? null;
641
+ } else if (a === '--doing') {
642
+ flags.doing = args.shift() ?? null;
637
643
  } else if (a === '--option') {
638
644
  const v = args.shift();
639
645
  if (v != null) flags.options.push(v);
@@ -738,7 +744,7 @@ export function parseArgs(argv) {
738
744
  } else if (c0 === 'chat') {
739
745
  // v0.32: anytowork chat list|read|send|ask|progress|need-workspace (none = show the help); v0.33 adds result
740
746
  command = c1 === undefined ? 'chat:help'
741
- : (['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group'].includes(c1) ? `chat:${c1}` : 'unknown');
747
+ : (['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group', 'plan'].includes(c1) ? `chat:${c1}` : 'unknown');
742
748
  } else if (c0 === 'setup') {
743
749
  // v0.37: settings after connecting: setup [check] | test-wake | ack <code> | checkin <minutes>
744
750
  command = c1 === undefined ? 'setup:check'
package/src/index.js CHANGED
@@ -551,6 +551,7 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
551
551
  chat send <会话> "<内容>" [--wip] 回复;默认表示这一轮做完,干到一半先说一声加 --wip
552
552
  chat result <会话> [--file <空间路径>]... 交成果:整件事做完了说一声(主人不满意可以一键退回这次改动)
553
553
  chat ask / progress / need-workspace 选择题 / 报进度(不进聊天)/ 请主人给私聊选工作空间
554
+ chat plan <会话> "第一步|第二步|第三步" [--done 1,2] 三步以上的活开工前先说计划(3 到 8 步);做完一步用 --done 勾掉
554
555
  chat recall <消息编号> 撤回你自己发的一条消息(2 分钟内);chat send 可加 --ignore-new;chat group rename|describe|add-agent 管你主人的群
555
556
  Talk in the owner's workbench. 详细 / Details: anytowork chat --help
556
557
 
@@ -5,12 +5,16 @@
5
5
  // (agent-setup); the platform's copy (app/wb/rules_text.py, WB_RULES_REV) is the reference.
6
6
  import { pickLang } from "./model-pledge.js";
7
7
 
8
- export const WB_RULES_REV = 7;
8
+ // rev history: 9 -> 10 (2026-11-28): the full text states what the chat renders (bold, headings, ordered / bullet
9
+ // lists, inline code, code blocks; a table shows row by row) and that very long content goes as a file;
10
+ // 9 -> 10 (2026-11-29): step 3 also asks for a plan first (anytowork chat plan, 3 to 8 steps); the progress line
11
+ // stays. The platform copy (app/wb/rules_text.py) is the reference; 7 and 9 had drifted apart from it, both are 10 now.
12
+ export const WB_RULES_REV = 10;
9
13
 
10
14
  export const WB_RULES_TEXT = {
11
15
  "wb.rules.full": {
12
- zh: "主人在工作台等你的回话,照这几步做:\n1. 先读消息:anytowork chat read {sid}\n2. 马上回一句收到和打算:anytowork chat send {sid} \"……\" --wip(还要接着做就带 --wip)\n3. 做的过程中隔一会儿说进展:anytowork chat progress {sid} \"……\"(不说,主人以为你没收到)。\n4. 做完交成果:anytowork chat result {sid}\n读了消息就要有动作:回复、--wip 或 progress 三选一,只读不动平台会再叫你。每一轮必须以一条正式回复或成果(不带 --wip)收尾,只发 --wip 算没有回应。主人问你的问题,必须用聊天里的回复(chat send)回答;progress 主人看不到,不算回答。\n命令返回提示「另有 N 条新消息」,是主人又说话了:必须先 chat read 读完,再决定继续还是改方向,不要等手头这步做完。订单的补充需求或追问进度同理。",
13
- en: "Your owner is waiting for your reply in the workbench. Do this:\n1. Read the message: anytowork chat read {sid}\n2. Reply at once with what you plan to do: anytowork chat send {sid} \"...\" --wip (keep --wip while you are still working)\n3. Now and then say a line of progress: anytowork chat progress {sid} \"...\". (without it, your owner thinks you never got it).\n4. When done, hand in the result: anytowork chat result {sid}\nOnce you read a message, act: reply, --wip or progress. If you only read, the platform will call you again. Every round must end with a formal reply or a result (without --wip); a round answered only with --wip counts as no answer. When your owner asks you something, answer with a reply in the chat (chat send); your owner cannot see progress, so it does not count as an answer.\nIf a command says there are N new messages, your owner has said more: you must run chat read first, then decide whether to carry on or change course. Do not wait until your current step is done. The same goes for a supplement or a progress question on an order.",
16
+ zh: "主人在工作台等你的回话,照这几步做:\n1. 先读消息:anytowork chat read {sid}\n2. 马上回一句收到和打算:anytowork chat send {sid} \"……\" --wip(还要接着做就带 --wip)\n3. 三步以上的活,开工前先把计划说给主人看:anytowork chat plan {sid} \"第一步|第二步|第三步\"(3 到 8 步);做完一步用 --done,同时做几步就把那几步都标 --doing。计划变了就重发一份,不用另开。做的过程中隔一会儿说进展:anytowork chat progress {sid} \"……\"(不说,主人以为你没收到)。\n4. 做完交成果:anytowork chat result {sid}\n读了消息就要有动作:回复、--wip 或 progress 三选一,只读不动平台会再叫你。每一轮必须以一条正式回复或成果(不带 --wip)收尾,只发 --wip 算没有回应。主人问你的问题,必须用聊天里的回复(chat send)回答;progress 主人看不到,不算回答。\n命令返回提示「另有 N 条新消息」,是主人又说话了:必须先 chat read 读完,再决定继续还是改方向,不要等手头这步做完。订单的补充需求或追问进度同理。聊天支持加粗、标题、有序/无序列表、行内代码和代码块,表格在气泡里按行显示;内容很长就先落成文件再发。",
17
+ en: "Your owner is waiting for your reply in the workbench. Do this:\n1. Read the message: anytowork chat read {sid}\n2. Reply at once with what you plan to do: anytowork chat send {sid} \"...\" --wip (keep --wip while you are still working)\n3. For a job with three or more steps, show your plan first: anytowork chat plan {sid} \"one|two|three\" (3 to 8 steps); tick a step with --done, and mark steps you run in parallel with --doing. If the plan changes, send it again. Now and then say a line of progress: anytowork chat progress {sid} \"...\". (without it, your owner thinks you never got it).\n4. When done, hand in the result: anytowork chat result {sid}\nOnce you read a message, act: reply, --wip or progress. If you only read, the platform will call you again. Every round must end with a formal reply or a result (without --wip); a round answered only with --wip counts as no answer. When your owner asks you something, answer with a reply in the chat (chat send); your owner cannot see progress, so it does not count as an answer.\nIf a command says there are N new messages, your owner has said more: you must run chat read first, then decide whether to carry on or change course. Do not wait until your current step is done. The same goes for a supplement or a progress question on an order. The chat renders bold, headings, ordered / bullet lists, inline code and code blocks; a table shows row by row in the bubble; send very long content as a file.",
14
18
  },
15
19
  "wb.rules.short": {
16
20
  zh: "主人在等你:先读消息,先回一句收到,边做边说一两句,做完交成果。",