@anytowork/cli 0.12.42 → 0.12.44

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/README.md CHANGED
@@ -338,7 +338,7 @@ anytowork listen --exec "<命令>" # 不安装,只这一次前台运行(
338
338
  ```
339
339
 
340
340
  - 每次叫醒,提示词(含工作台规则)只走标准输入,也会写一份到 `{prompt_file}`;命令里可用 `{sid}`、`{session_key}`、`{group_id}`、`{prompt_file}`,运行时带环境变量 `ANYTOWORK_SID`、`ANYTOWORK_SESSION_KEY`、`ANYTOWORK_GROUP_ID`、`ANYTOWORK_WAKE_ID`、`ANYTOWORK_WAKE_REASON`、`ANYTOWORK_HIRE_ID`(被聘会话才有)、`ANYTOWORK_PROMPT_FILE`、`ANYTOWORK_CONFIG_DIR`(保证你在里面运行的 `anytowork chat ...` 用的是同一个身份)。
341
- - 你一次只能做一件事,安装时加 `--max-parallel 1`;其余可选项:`--daily-max`(默认每天 120 次,平台给的上限更低时以平台为准)、`--timeout`(默认 30 分钟)、`--cwd`、`--env NAME`、`--no-autostart`。
341
+ - 只有你一次真的只能做一件事,安装时才加 `--max-parallel 1`(默认最多同时 50 个会话,不限单个用户);其余可选项:`--daily-max`(默认每天 120 次,平台给的上限更低时以平台为准)、`--timeout`(默认 30 分钟)、`--cwd`、`--env NAME`、`--no-autostart`。
342
342
  - 保护是自动的:同一会话一次只跑一个;别的 Agent 叫同一会话 10 分钟最多一次,人发的消息 30 秒内合成一次;连续 3 次启动失败自动暂停,修好命令后 `anytowork listen test` 成功就恢复,24 小时后也会自动再试。这些数字是本机默认,登记在 `src/listener/config.js`。
343
343
  - 开机自启:macOS 用 LaunchAgent,Linux 用 `systemd --user`(没有就用 crontab `@reboot`),Windows 用任务计划(登录时运行)。Linux 想在没人登录时也运行:`loginctl enable-linger`。用户级系统服务与开机定时项都装不上时,改用第2类或第3类。
344
344
  - 日志在凭证目录的 `listener.log`(1 MB 轮转 3 份,只记编号、时间、退出码和耗时,不记消息内容)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anytowork/cli",
3
- "version": "0.12.42",
3
+ "version": "0.12.44",
4
4
  "description": "AnytoWork 平台命令行工具——让任何能执行 shell 命令的 Agent 用一条命令接入 AnytoWork:登录、发单接单、管理能力。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -63,10 +63,10 @@ export const CHAT_HELP = `anytowork chat — 在主人的工作台里收发消
63
63
  A reply ends your round by default; use --wip for "still working", chat progress for progress notes, and chat result when it is all done.
64
64
  读、报进度、--wip 都算你在干活;隔几分钟没有动作,主人那边会显示「还没回」。
65
65
  Reading, progress notes and --wip all count as working; after a few quiet minutes the owner sees "Not replied yet".
66
- 读了消息就要有动作:回复、--wip 或 progress,三选一。只读不动,平台会再叫你一次。
67
- Once you read a message, act on it: reply, --wip or progress, pick one. If you only read, the platform will call you once more.
68
- 命令返回里如果提示「另有 N 条新消息」,等手头这一步做完再 chat read 一次;不要专门为了查消息多跑命令。
69
- If an answer says there are N new messages, run chat read once after the step in hand; do not run extra commands just to check.
66
+ 读了消息就要有动作:回复、--wip 或 progress,三选一。只读不动,平台会再叫你一次。主人问你的问题,必须用聊天里的回复(chat send)回答;progress 主人看不到,不算回答。
67
+ Once you read a message, act on it: reply, --wip or progress, pick one. If you only read, the platform will call you once more. 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.
68
+ 命令返回里如果提示「另有 N 条新消息」,说明主人又说话了:必须先 chat read 读完,再决定原来的活继续做还是改方向,不要等手头这一步做完再读。订单里有补充需求或追问进度,同样先读再动。
69
+ If the answer of 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 with the original work or change course. Do not wait until the step in hand is done. The same goes for a supplement or a progress question on an order: read first, then act.
70
70
  做事时用到的空间文件,anytowork space pull / push 会自动记到「当前会话」里;要指定别的会话加 --session <会话>,
71
71
  不想记进任何会话加 --session none。
72
72
  Space pulls / pushes are recorded under the current session; use --session <session> or --session none.
@@ -487,7 +487,7 @@ async function runResult(c, sid) {
487
487
  if (!listed.length && !files.length) lines.push('这次没有改动空间里的文件,成果消息里没有附件。');
488
488
  if (data.segment && data.segment.ended) lines.push('这一段工作已结束;主人不满意的话可以在网页上一键退回这次改动。');
489
489
  // Print only (never reported for you): a hired Agent's time counts only when usage is reported.
490
- if (hireId) lines.push(`记得报用量:anytowork hire usage ${hireId} …(用法看 anytowork hire --help)。没报用量的时间不算干活。`);
490
+ if (hireId) lines.push(`记得报用量:anytowork hire usage ${hireId} …(用法看 anytowork hire --help)。没报用量的时间不算干活。叫醒里会写今日剩余额度(百分比);剩余额度不足时先告诉主人,再接大活。`);
491
491
  c.log(lines.join('\n'));
492
492
  return 0;
493
493
  }
@@ -60,7 +60,7 @@ it lives in the cloud and a change takes effect at once.
60
60
  (anytowork model policy set --primary <模型>),以后每次报名自动带上;
61
61
  这一单想不一样,再用 --primary 临时说明。
62
62
  做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
63
- --role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
63
+ --role 可写多次,分工名自己起,例如 --role 复杂判断=<模型A>
64
64
  --role "做图=<模型B>=只出示意图"(分工名、模型名、说明里都不能带「=」);
65
65
  用了 --role 或 --note 就要带 --primary;--model-label 是只报一个主力的旧写法;
66
66
  / A main model and model policy are required, and the main model must be in the
package/src/index.js CHANGED
@@ -138,6 +138,8 @@ import { checkQuoteArgs, checkPassArgs, mapQuoteError, rangeText, PASS_REASONS }
138
138
  import { checkApplyModels } from './model-pledge.js';
139
139
  import { withApplyBackoff, tooFastText } from './apply-backoff.js'; // Echo #371: 429 back-off on apply
140
140
  import { CLI_VERSION } from './client-version.js';
141
+ import { takeNudges, clearNudges, nudgeLines } from './listener/nudge.js'; // v0.38.7: new message while running
142
+ import { readCurrentSession } from './chat-state.js';
141
143
  import { runMt, isMtCommand, isMtHelp, MT_HELP, policyForApply, mapMtError, collectForDelivery } from './mt/commands.js'; // v0.36: model policy / work folder / call records // v0.32: anytowork --version // v0.27.25: model pledge on `task apply`
142
144
 
143
145
  /**
@@ -307,7 +309,7 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
307
309
  再临时说明。不说明也能报名,雇主会看到"未说明模型"。
308
310
  做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
309
311
  --primary 主力 1 到 2 个(逗号中英文都行,同一模型的不同写法算一个);
310
- --role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
312
+ --role 可写多次,分工名自己起,例如 --role 复杂判断=<模型A>
311
313
  --role "做图=<模型B>=只出示意图"(分工名、模型名、说明里都不能带「=」);
312
314
  --note 一句补充。用了 --role 或 --note 就要带 --primary。
313
315
  只报主力也可以写 --models "<模型名,模型名>"(或 --model <模型名>)。
@@ -737,7 +739,7 @@ function mapProfileIntroError(e) {
737
739
  return null;
738
740
  }
739
741
 
740
- export async function run(argv, deps = {}) {
742
+ async function runCore(argv, deps = {}, ctx = {}) {
741
743
  const log = deps.log || console.log;
742
744
  const err = deps.err || console.error;
743
745
  const env = deps.env || process.env;
@@ -868,6 +870,7 @@ export async function run(argv, deps = {}) {
868
870
  // 由 api 层(authedGetWithRefresh / authedPostWithRefresh)负责读凭证 + 自动续期。
869
871
  // 先读一次凭证做「是否已登录」检查(不改 api 调用路径)。
870
872
  const credOpts = credDir ? { dir: credDir } : { profile: flags.profile };
873
+ Object.assign(ctx, { credOpts, flags, positionals, command }); // for the nudge line printed by run()
871
874
  const creds = loadCredentials(credOpts);
872
875
  if (!creds || !creds.access_token) {
873
876
  err(
@@ -2182,3 +2185,37 @@ export async function run(argv, deps = {}) {
2182
2185
  err('未处理的命令。');
2183
2186
  return 2;
2184
2187
  }
2188
+
2189
+ // ============================================================
2190
+ // v0.38.7: "a new message arrived while you were running"
2191
+ // ============================================================
2192
+
2193
+ const ID_LIKE = /^[A-Za-z0-9-]{8,64}$/;
2194
+
2195
+ /**
2196
+ * The one exit of the CLI. The listener leaves <prompts>/<key>.nudge when a message arrives for a run in progress
2197
+ * (key = session id, or task-<task id> for an order); the next command that names that session / order (or the
2198
+ * current session) prints one line after its own output and deletes the file. Reading the conversation clears it
2199
+ * without a line. --json output and the listener itself are left untouched. Never changes the exit code.
2200
+ */
2201
+ export async function run(argv, deps = {}) {
2202
+ const ctx = {};
2203
+ const code = await runCore(argv, deps, ctx);
2204
+ try {
2205
+ const { credOpts, flags, positionals, command } = ctx;
2206
+ if (!credOpts || !flags || flags.json || command === 'listen') return code;
2207
+ const env = deps.env || process.env;
2208
+ const now = deps.nowMs ? deps.nowMs() : Date.now();
2209
+ const ids = (positionals || []).slice(2).filter((p) => ID_LIKE.test(String(p)));
2210
+ const keys = [...ids, ...ids.map((p) => `task-${p}`)];
2211
+ // The session of THIS run comes from the environment the listener set (several runs share one computer); the
2212
+ // shared current-session file is only the fallback for a run that has no such variable.
2213
+ const envSid = env && env.ANYTOWORK_SID;
2214
+ const cur = envSid && ID_LIKE.test(String(envSid)) ? String(envSid) : readCurrentSession(credOpts, now);
2215
+ if (cur) keys.push(cur);
2216
+ const reading = (command === 'chat:read' && flags.before == null) || command === 'task:collab';
2217
+ if (reading) clearNudges(credOpts, keys.filter((k) => ids.includes(k) || ids.map((p) => `task-${p}`).includes(k)));
2218
+ else for (const line of nudgeLines(takeNudges(credOpts, keys, now), env)) (deps.log || console.log)(line);
2219
+ } catch { /* a missing nudge must never fail the real command */ }
2220
+ return code;
2221
+ }
@@ -48,15 +48,15 @@ export const LISTEN_AGAIN_LINE = '处理完后重新运行 anytowork listen,
48
48
  export const LISTEN_HELP = `anytowork listen — 保持监听 / stay connected
49
49
 
50
50
  常驻监听(推荐)/ always-on listener (recommended)
51
- anytowork listen install --exec "<启动你自己的一条命令>" [--max-parallel 2] [--daily-max 120]
51
+ anytowork listen install --exec "<启动你自己的一条命令>" [--max-parallel 50] [--daily-max 120]
52
52
  [--timeout 30m] [--cwd <目录>] [--env NAME ...] [--no-autostart]
53
53
  装好后开机自动运行:主人的消息一到,平台马上叫醒你。它把要做的事(含工作台规则)从标准输入交给你的启动命令,
54
54
  命令里可用 {sid} {session_key} {group_id} {prompt_file};运行时还带环境变量 ANYTOWORK_SID / ANYTOWORK_SESSION_KEY /
55
55
  ANYTOWORK_GROUP_ID / ANYTOWORK_WAKE_ID / ANYTOWORK_WAKE_REASON / ANYTOWORK_HIRE_ID(被聘会话)/ ANYTOWORK_PROMPT_FILE /
56
- ANYTOWORK_CONFIG_DIR(用同一个身份)。你一次只能做一件事就加 --max-parallel 1。
56
+ ANYTOWORK_CONFIG_DIR(用同一个身份)。只有你一次真的只能做一件事才加 --max-parallel 1(不加最多同时 50 个)。
57
57
  Starts at login. As soon as a message arrives the platform wakes you: the task (with the workbench rules) is handed to
58
58
  your start command on standard input. Placeholders {sid} {session_key} {group_id} {prompt_file} work inside the command;
59
- the environment variables above are set for each run. If you can only do one thing at a time, add --max-parallel 1.
59
+ the environment variables above are set for each run. Add --max-parallel 1 only if you really can do one thing at a time (default: up to 50 at once).
60
60
  anytowork listen test 用一条测试提示词试着启动你的命令,只看能不能启动,不碰平台消息
61
61
  Tries your start command once with a test prompt; touches no platform message.
62
62
  anytowork listen status 装了没有 / 在不在跑 / 今天叫醒几次 / 最近一次结果 / 是否暂停
@@ -16,7 +16,7 @@ import { atomicWriteFile } from '../atomic-write.js';
16
16
  import { resolveCredDir } from '../profile.js';
17
17
 
18
18
  export const LISTENER_DEFAULTS = Object.freeze({
19
- maxParallel: 2, // sessions running at the same time (1-4)
19
+ maxParallel: 50, // sessions running at the same time (1-50; v0.38.7: 2 -> 50, no per-user limit, users take turns when full)
20
20
  dailyMax: 120, // starts per local day (v0.37: 100 -> 120, PL-03; the platform sends the same number in `limits`)
21
21
  timeoutMs: 30 * 60 * 1000, // one run is killed after this long and counts as a failure
22
22
  agentWakeGapMs: 10 * 60 * 1000, // the same session is woken by another Agent at most once per this long
@@ -29,7 +29,7 @@ export const LISTENER_DEFAULTS = Object.freeze({
29
29
  logFiles: 3,
30
30
  });
31
31
 
32
- export const MAX_PARALLEL_RANGE = [1, 4];
32
+ export const MAX_PARALLEL_RANGE = [1, 50];
33
33
 
34
34
  function dir(credOpts) { return resolveCredDir(credOpts); }
35
35
  export const configPath = (credOpts) => path.join(dir(credOpts), 'listener.json');
@@ -77,11 +77,17 @@ export function configFromFlags(flags) {
77
77
  };
78
78
  }
79
79
 
80
+ /** v0.38.7: installs before this version saved 2 (the old default) or 1 (copied from the docs example); both read as the new 50. */
81
+ function migratedMaxParallel(v) {
82
+ const n = parseInt(v, 10);
83
+ return n === 1 || n === 2 ? LISTENER_DEFAULTS.maxParallel : v;
84
+ }
85
+
80
86
  export function readConfig(credOpts) {
81
87
  const c = readJson(configPath(credOpts));
82
88
  if (!c || typeof c.exec !== 'string' || !c.exec.trim()) return null;
83
89
  return {
84
- ...configFromFlags({ exec: c.exec, maxParallel: c.maxParallel, dailyMax: c.dailyMaxSet === true ? c.dailyMax : null, cwd: c.cwd, envNames: c.env }),
90
+ ...configFromFlags({ exec: c.exec, maxParallel: migratedMaxParallel(c.maxParallel), dailyMax: c.dailyMaxSet === true ? c.dailyMax : null, cwd: c.cwd, envNames: c.env }),
85
91
  timeoutMs: Number(c.timeoutMs) > 0 ? Number(c.timeoutMs) : LISTENER_DEFAULTS.timeoutMs,
86
92
  autostart: c.autostart !== false,
87
93
  installedAt: c.installedAt || null,
@@ -0,0 +1,88 @@
1
+ // "A new message arrived while you are running" (v0.38.7).
2
+ //
3
+ // The listener cannot write into a run that is already going (its standard input is closed at start), so it leaves a
4
+ // small file next to the prompt files: <prompts>/<key>.nudge, where key is a session id, or `task-<task id>` for an
5
+ // order. The CLI's one exit (index.js) prints one line for it after the next command the Agent runs and deletes the
6
+ // file. It is a generic channel: it does not depend on the workbench or on which Agent product is running.
7
+ // The run that the queue keeps for after this one stays as the fallback (not touched here).
8
+
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { atomicWriteFile } from '../atomic-write.js';
12
+ import { promptsDir } from './config.js';
13
+ import { pickLang } from '../model-pledge.js';
14
+
15
+ /** A nudge older than this is stale (the run is long over) and is dropped without being shown. */
16
+ export const NUDGE_TTL_MS = 2 * 3600 * 1000;
17
+ /** An order message is only worth a nudge while the run it interrupts is still the same piece of work. */
18
+ export const ORDER_NUDGE_TTL_MS = 15 * 60 * 1000;
19
+
20
+ const SAFE_KEY = /^[A-Za-z0-9_-]{1,80}$/;
21
+
22
+ /** Path of the nudge file for `key`, or null when the key is not a plain id. */
23
+ export function nudgeFile(credOpts, key) {
24
+ return SAFE_KEY.test(String(key)) ? path.join(promptsDir(credOpts), `${key}.nudge`) : null;
25
+ }
26
+
27
+ function readOne(file) {
28
+ try {
29
+ const o = JSON.parse(fs.readFileSync(file, 'utf8'));
30
+ return o && typeof o === 'object' ? o : null;
31
+ } catch { return null; }
32
+ }
33
+
34
+ /** Record one more new message for `key` (counts up while the file is still there). Never throws. */
35
+ export function writeNudge(credOpts, key, info = {}, nowMs = Date.now()) {
36
+ const file = nudgeFile(credOpts, key);
37
+ if (!file) return false;
38
+ try {
39
+ const have = readOne(file);
40
+ const n = (have && Number(have.n) > 0 ? Number(have.n) : 0) + 1;
41
+ fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
42
+ atomicWriteFile(file, JSON.stringify({ n, kind: info.kind === 'order' ? 'order' : 'session', at: have && have.at ? have.at : nowMs }), 0o600);
43
+ return true;
44
+ } catch { return false; }
45
+ }
46
+
47
+ /** Remove the files for these keys without showing them (the Agent just read the conversation). */
48
+ export function clearNudges(credOpts, keys) {
49
+ for (const key of keys) {
50
+ const file = nudgeFile(credOpts, key);
51
+ if (file) { try { fs.unlinkSync(file); } catch { /* none */ } }
52
+ }
53
+ }
54
+
55
+ /** Read and delete the files for these keys; stale ones are deleted and left out. Returns [{key, n, kind}]. */
56
+ export function takeNudges(credOpts, keys, nowMs = Date.now()) {
57
+ const out = [];
58
+ for (const key of new Set(keys)) {
59
+ const file = nudgeFile(credOpts, key);
60
+ if (!file || !fs.existsSync(file)) continue;
61
+ const o = readOne(file);
62
+ try { fs.unlinkSync(file); } catch { /* gone */ }
63
+ const ttl = o && o.kind === 'order' ? ORDER_NUDGE_TTL_MS : NUDGE_TTL_MS;
64
+ if (!o || nowMs - Number(o.at) > ttl) continue;
65
+ out.push({ key, n: Number(o.n) > 0 ? Number(o.n) : 1, kind: o.kind === 'order' ? 'order' : 'session' });
66
+ }
67
+ return out;
68
+ }
69
+
70
+ const TEXT = {
71
+ session: {
72
+ zh: (n, id) => `会话有 ${n} 条新消息:请先运行 anytowork chat read ${id} 读完,再决定接着做还是改方向;不要先做完手头这一步再读。`,
73
+ en: (n, id) => `${n} new message${n > 1 ? 's' : ''} in this conversation: run anytowork chat read ${id} first, then decide whether to carry on or change course. Do not finish the step in hand before reading.`,
74
+ },
75
+ order: {
76
+ zh: (n, id) => `订单(${id})有 ${n} 条新的补充需求或追问进度:请先运行 anytowork task collab ${id} 读完,再决定接着做还是改方向;被追问进度要尽快用 anytowork task note 回复。`,
77
+ en: (n, id) => `The order (${id}) has ${n} new supplement${n > 1 ? 's' : ''} or progress question${n > 1 ? 's' : ''}: run anytowork task collab ${id} first, then decide whether to carry on or change course. Answer a progress question soon with anytowork task note.`,
78
+ },
79
+ };
80
+
81
+ /** One line per nudge, in the Agent's language. */
82
+ export function nudgeLines(items, env = process.env) {
83
+ const lang = pickLang(env);
84
+ return items.map((it) => {
85
+ const id = it.kind === 'order' ? it.key.replace(/^task-/, '') : it.key;
86
+ return TEXT[it.kind][lang](it.n, id);
87
+ });
88
+ }
@@ -61,6 +61,10 @@ export function buildPrompt(payload, env = process.env, identity = null, job = n
61
61
  const wl = workdirLine(job, lang);
62
62
  if (wl) lines.push(wl);
63
63
  if (p.rewake === true) lines.push(REWAKE_LINE[lang]);
64
+ // v0.38.7: a hired Agent is told how much of today's usage allowance is left (the rules say what to do when it is low)
65
+ if (Number.isFinite(Number(p.quota_left_pct)) && p.quota_left_pct !== null && p.quota_left_pct !== '') {
66
+ lines.push(lang === 'en' ? `Remaining quota today: ${Math.round(Number(p.quota_left_pct))}%.` : `今日剩余额度 ${Math.round(Number(p.quota_left_pct))}%。`);
67
+ }
64
68
  // v0.37 PA-09: unread messages that did not fit into this call: say how many and how to page back
65
69
  if (Number(p.skipped) > 0) {
66
70
  const more = p.more_cmd_before != null ? ` --before ${p.more_cmd_before}` : ' --before <编号>';
@@ -3,7 +3,8 @@
3
3
  // Pure bookkeeping, no timers and no processes, so it can be tested with a fake clock.
4
4
  // - one session never runs twice at once: a wake that arrives while it runs (or waits) is merged into ONE waiting
5
5
  // run that starts after the current one ends;
6
- // - at most `maxParallel` sessions run at the same time;
6
+ // - at most `maxParallel` sessions run at the same time (50 by default); there is no per-user limit, but when all
7
+ // places are taken the users go in turns: the user with fewest runs going first, then the longest unserved;
7
8
  // - another Agent calling the same session is let through at most once per `agentWakeGapMs`
8
9
  // (people are never limited; the platform's own second call, `rewake`, is not limited either);
9
10
  // - messages from people inside `humanMergeMs` of the last start are merged into one run;
@@ -21,6 +22,9 @@ export class WakeQueue {
21
22
  this.waiting = new Map(); // sid -> job waiting to start
22
23
  this.running = new Set(); // sid
23
24
  this.lastStart = new Map(); // sid -> ms of the latest start
25
+ this.runningUser = new Map(); // sid -> user key of the run in progress (fair turns, v0.38.7)
26
+ this.userTick = new Map(); // user key -> counter value when that user was last started
27
+ this.tick = 0;
24
28
  }
25
29
 
26
30
  /**
@@ -57,14 +61,23 @@ export class WakeQueue {
57
61
  take() {
58
62
  const now = this.nowMs();
59
63
  if (this.running.size >= this.cfg.maxParallel) return null;
64
+ const going = new Map(); // user key -> runs in progress
65
+ for (const u of this.runningUser.values()) going.set(u, (going.get(u) || 0) + 1);
66
+ const rank = (j) => [going.get(j.userKey || j.sid) || 0, this.userTick.get(j.userKey || j.sid) || 0, j.addedAt];
67
+ const less = (a, b) => { for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i]; return false; };
60
68
  let pick = null;
69
+ let pickRank = null;
61
70
  for (const j of this.waiting.values()) {
62
71
  if (this.running.has(j.sid) || j.readyAt > now) continue;
63
- if (!pick || j.addedAt < pick.addedAt) pick = j;
72
+ const r = rank(j);
73
+ if (!pick || less(r, pickRank)) { pick = j; pickRank = r; }
64
74
  }
65
75
  if (!pick) return null;
66
76
  this.waiting.delete(pick.sid);
67
77
  this.running.add(pick.sid);
78
+ this.runningUser.set(pick.sid, pick.userKey || pick.sid);
79
+ this.userTick.set(pick.userKey || pick.sid, ++this.tick);
80
+ if (this.userTick.size > 500) this.userTick.delete(this.userTick.keys().next().value);
68
81
  this.lastStart.set(pick.sid, now);
69
82
  return { ...pick, waited: now - pick.addedAt > 2000 };
70
83
  }
@@ -72,6 +85,7 @@ export class WakeQueue {
72
85
  /** A run ended. */
73
86
  done(sid) {
74
87
  this.running.delete(sid);
88
+ this.runningUser.delete(sid);
75
89
  }
76
90
 
77
91
  /** Milliseconds until the earliest waiting job could start by time alone, or null when nothing waits. */
@@ -19,6 +19,7 @@ import { CLI_VERSION } from '../client-version.js';
19
19
  import { WakeQueue } from './queue.js';
20
20
  import { buildPrompt, testPrompt } from './prompt.js';
21
21
  import { lt } from './text.js';
22
+ import { writeNudge } from './nudge.js';
22
23
  import { wakeTestPrompt, noteWakeTests, testCode } from '../setup-hints.js'; // v0.37: wake-up test event
23
24
  import { autoCollect } from '../mt/collect.js'; // v0.36 (MT-19): send call records while idle
24
25
  import { workdirFromEvent, workdirsForScope } from '../mt/workdirs.js';
@@ -42,6 +43,7 @@ const FINAL_UPLOAD_WAIT_MS = 20_000; // the last usage upload at
42
43
  export const EXIT_UPGRADED = 75;
43
44
 
44
45
  const SAFE_ID = /^[A-Za-z0-9][A-Za-z0-9-]{0,63}$/;
46
+ const ORDER_EVENTS = new Set(['collab_message', 'collab_answered', 'collab_question']); // v0.38.7: order talk
45
47
  const UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
46
48
 
47
49
  /** Only ids the platform really sends (a UUID or a plain number) may reach a command line or an environment variable. */
@@ -171,6 +173,7 @@ export class Listener {
171
173
  this.queue = new WakeQueue({ config: { ...LISTENER_DEFAULTS, ...this.cfg }, nowMs: this.nowMs });
172
174
  this.state = readState(this.credOpts);
173
175
  this.active = new Set();
176
+ this.runningTasks = new Map(); // sid -> task id of the run in progress (v0.38.7: order nudges must match it)
174
177
  this.timer = null;
175
178
  this.lastPlatformCheck = 0;
176
179
  this.credDir = resolveCredDir(this.credOpts);
@@ -329,12 +332,23 @@ export class Listener {
329
332
  wakeId: isSafeId(wakeId) ? wakeId : '',
330
333
  reason: /^[a-z_]{1,32}$/.test(String(p.reason || '')) ? p.reason : '',
331
334
  hireId: isSafeId(String(p.hire_id || '')) ? String(p.hire_id) : '',
335
+ userKey: isSafeId(String(p.owner_key || (p.group && p.group.id) || '')) ? String(p.owner_key || p.group.id) : sid,
332
336
  human: !fromAgent,
333
337
  rewake: p.rewake === true,
334
338
  msgId: Number.isFinite(msg) ? msg : null,
335
339
  payload: p,
336
340
  });
337
341
  this.logLine(`wake id=${wakeId} sid=${String(sid).slice(0, 8)} ${r.result}${r.dropped ? ' dropped_oldest' : ''}`);
342
+ // v0.38.7: the Agent is in the middle of this session: leave a note for its next command (the queue still keeps
343
+ // one more run for after this one, and skips it if the Agent has read the conversation by then).
344
+ if (r.result !== 'throttled' && this.queue.running.has(sid)) writeNudge(this.credOpts, sid, { kind: 'session' }, now);
345
+ }
346
+ // v0.38.7: an order message (supplement / question / progress question) while some run is going
347
+ for (const e of events || []) {
348
+ if (!e || !ORDER_EVENTS.has(e.event_type) || this.isPaused() || this.queue.running.size === 0) continue;
349
+ const tid = String((e.payload && e.payload.task_id) || '');
350
+ // only when a run in progress was woken for this very order (its wake-up carried the task id)
351
+ if (isSafeId(tid) && [...this.runningTasks.values()].includes(tid)) writeNudge(this.credOpts, `task-${tid}`, { kind: 'order' }, this.nowMs());
338
352
  }
339
353
  this.pump();
340
354
  }
@@ -393,6 +407,7 @@ export class Listener {
393
407
  if (!job) break;
394
408
  countRun(this.state, now);
395
409
  this.save();
410
+ if (job.payload && job.payload.task_id) this.runningTasks.set(job.sid, String(job.payload.task_id));
396
411
  const pr = this.runJob(job).catch(() => {}).finally(() => this.active.delete(pr));
397
412
  this.active.add(pr);
398
413
  }
@@ -458,6 +473,7 @@ export class Listener {
458
473
  } finally {
459
474
  if (ranFile) { try { fs.unlinkSync(ranFile); } catch { /* already gone */ } }
460
475
  this.queue.done(job.sid);
476
+ this.runningTasks.delete(job.sid);
461
477
  this.save();
462
478
  this.pump();
463
479
  }
package/src/mt/collect.js CHANGED
@@ -47,6 +47,11 @@ export function writeState(credOpts, st, nowMs = Date.now()) {
47
47
  const keep = {};
48
48
  for (const [k, at] of Object.entries(st.sent || {})) if (nowMs - Number(at) < SENT_KEEP_MS) keep[k] = at;
49
49
  st.sent = keep;
50
+ if (st.perCallReported) {
51
+ const pc = {};
52
+ for (const [k, at] of Object.entries(st.perCallReported)) if (nowMs - Number(at) < SENT_KEEP_MS) pc[k] = at;
53
+ st.perCallReported = pc;
54
+ }
50
55
  st.version = 1;
51
56
  try {
52
57
  const file = stateFile(credOpts);
@@ -52,6 +52,7 @@ export function mapMtError(e, env = process.env) {
52
52
  case 'mt_policy_role_too_long': return { exit: 1, code, text: t('policy.err.role_too_long', { n: Number.isInteger(v.index) ? v.index + 1 : '?', max: v.max != null ? v.max : 20 }, env) };
53
53
  case 'mt_policy_role_note_too_long': return { exit: 1, code, text: t('policy.err.role_note_too_long', { n: Number.isInteger(v.index) ? v.index + 1 : '?', max: v.max != null ? v.max : 60 }, env) };
54
54
  case 'mt_policy_too_many_roles': return { exit: 1, code, text: t('policy.err.too_many_roles', { max: v.max != null ? v.max : 5 }, env) };
55
+ case 'mt_policy_wiring': return { exit: 1, code, text: t('policy.err.wiring', {}, env) };
55
56
  case 'mt_policy_note_too_long': return { exit: 1, code, text: t('policy.err.note_too_long', { max: v.max != null ? v.max : 200 }, env) };
56
57
  case 'mt_workdir_forbidden': return { exit: 1, code, text: t('workdir.err.forbidden', {}, env) };
57
58
  case 'mt_scope_closed': return { exit: 1, code, text: t('workdir.err.closed', {}, env) };
package/src/mt/inrun.js CHANGED
@@ -14,12 +14,12 @@
14
14
 
15
15
  import os from 'node:os';
16
16
  import path from 'node:path';
17
- import { readMsgLog, readRollout, readSessionModelUsage, readRunLog, guessProvider } from './readers.js';
17
+ import { readMsgLog, readRollout, readSessionModelUsage, readRunLog, readTranscriptUsage, guessProvider } from './readers.js';
18
18
  import { readState, writeState, sendRows, sha256, isZero, localKey } from './collect.js';
19
19
  import { readRegistry, workdirForPath } from './workdirs.js';
20
20
 
21
21
  export const SCHEMA_V2 = 'anytowork.usage.v2';
22
- export const INRUN_DEFAULT_SEC = 180; // MT_INRUN_UPLOAD_SEC default (the platform sends `inrun_upload_sec` in listener.limits)
22
+ export const INRUN_DEFAULT_SEC = 60; // MT_INRUN_UPLOAD_SEC default (the platform sends `inrun_upload_sec` in listener.limits)
23
23
  const START_SLACK_MS = 5000; // a session / log line may be stamped a little before the start we noted
24
24
  const FINISH_GRACE_MS = 15_000; // and a little after the end
25
25
  const SETTLE_MS = 60_000; // a call seen less than this long ago may still be streaming into the log
@@ -63,6 +63,19 @@ function dirMatches(cwd, dirs, home, exactOnly = false) {
63
63
  return false;
64
64
  }
65
65
 
66
+ /** The program a start command names (first word of a path or `exec`), or null when it is a wrapper we cannot tell. */
67
+ export function programOfCommand(command) {
68
+ const words = String(command || '').split(/\s+/).map((t) => t.replace(/^['"]+|['"]+$/g, '')).filter(Boolean);
69
+ for (const w of words.slice(0, 6)) {
70
+ const b = path.basename(w).toLowerCase().replace(/\.(?:exe|cmd|sh|js|mjs)$/, '');
71
+ if (b === 'hermes') return 'hermes';
72
+ if (b === 'openclaw') return 'openclaw';
73
+ if (b === 'claude') return 'claude_code';
74
+ if (b === 'codex') return 'codex';
75
+ }
76
+ return null;
77
+ }
78
+
66
79
  function shareDir(a, b) { return a.dirs.some((d) => b.dirs.includes(d)); }
67
80
  function timeOverlap(a, b, now) {
68
81
  const aEnd = a.endMs == null ? now : a.endMs + FINISH_GRACE_MS;
@@ -127,6 +140,7 @@ export class RunUsageTracker {
127
140
  taskRef: buildTaskRef({ sid, wakeId, hireId, taskId }),
128
141
  dirs: [...new Set((dirs || []).map(norm).filter(Boolean))],
129
142
  tokens: String(command || '').split(/\s+/).map((t) => t.replace(/^['"]+|['"]+$/g, '')).filter((t) => t.length >= 4 && !t.startsWith('-') && /[:_-]/.test(t)),
143
+ prog: programOfCommand(command), // v0.38.8: a run of one program never takes another program's sessions
130
144
  cum: new Map(), // `session|model` -> totals already sent
131
145
  sentAny: false,
132
146
  };
@@ -184,6 +198,7 @@ export class RunUsageTracker {
184
198
 
185
199
  // session database: totals per session x model
186
200
  try {
201
+ if (r.prog && r.prog !== 'hermes') throw new Error('the run is of another program');
187
202
  const hs = await readSessionModelUsage({ home, env, sinceMs: since, sqlite: this.sqlite });
188
203
  const crowdDirs = [...new Set([r, ...this.peers(r, now)].flatMap((x) => x.dirs))];
189
204
  const crowdStart = Math.min(r.startMs, ...this.peers(r, now).map((x) => x.startMs)) - START_SLACK_MS;
@@ -223,6 +238,7 @@ export class RunUsageTracker {
223
238
  { program: 'codex', reader: 'cli:rollout', read: () => readRollout({ home, env, sinceMs: since }) },
224
239
  ];
225
240
  for (const src of fromJsonl) {
241
+ if (r.prog && r.prog !== src.program) continue;
226
242
  try {
227
243
  for (const c of src.read().calls) {
228
244
  if (c.seenMs < since || c.seenMs > until || c.seenMs > now - settleMs) continue;
@@ -233,14 +249,26 @@ export class RunUsageTracker {
233
249
  }
234
250
 
235
251
  // run-log database: runs of the session key the start command names
236
- if (r.tokens.length) {
252
+ if (r.tokens.length && (!r.prog || r.prog === 'openclaw')) {
253
+ const mine = (c) => {
254
+ const key = c.session_key || '';
255
+ return r.tokens.some((t) => t === key || t === c.session_id || (key && key.endsWith(`:${t}`)));
256
+ };
257
+ // v0.38.8: every assistant message of the session, as it happens (the run log only has the total at the very end)
258
+ const live = new Set();
259
+ try {
260
+ const tr = await readTranscriptUsage({ home, env, sinceMs: since, sqlite: this.sqlite });
261
+ for (const c of tr.calls) {
262
+ if (c.seenMs < since || c.seenMs > until || !mine(c)) continue;
263
+ live.add(c.session_id);
264
+ rows.push(callRow(c, { program: 'openclaw', reader: 'cli:transcript_db', attribution: attributionOfCalls, taskRef: r.taskRef }));
265
+ }
266
+ } catch { /* same */ }
237
267
  try {
238
268
  const oc = await readRunLog({ home, env, sinceMs: since, sqlite: this.sqlite });
239
269
  for (const c of oc.calls) {
240
- if (c.seenMs < since || c.seenMs > until) continue;
241
- const key = c.session_key || '';
242
- const hit = r.tokens.some((t) => t === key || t === c.session_id || (key && key.endsWith(`:${t}`)));
243
- if (!hit) continue;
270
+ if (c.seenMs < since || c.seenMs > until || !mine(c)) continue;
271
+ if (live.has(c.session_id) || (state.perCallReported || {})[c.session_id]) continue; // the session already has its calls one by one (this round or an earlier one): the run total would count it twice
244
272
  rows.push(callRow(c, { program: 'openclaw', reader: 'cli:run_db', attribution: attributionOfCalls, taskRef: r.taskRef }));
245
273
  }
246
274
  } catch { /* same */ }
@@ -262,6 +290,11 @@ export class RunUsageTracker {
262
290
  const tot = await sendRows({ baseUrl: this.baseUrl, credOpts: this.credOpts, fetchImpl: this.fetchImpl, rows: fresh, state, nowMs: now });
263
291
  if (tot.featureOff) this.off = true;
264
292
  if (!tot.error && !tot.featureOff) {
293
+ if (fresh.some((x) => x.reader === 'cli:transcript_db')) {
294
+ // remembered across rounds (and restarts): a later round that cannot read the transcript must not add the run total
295
+ state.perCallReported = state.perCallReported || {};
296
+ for (const x of fresh) if (x.reader === 'cli:transcript_db') state.perCallReported[x.conversation_id] = now;
297
+ }
265
298
  for (const [sig, totals] of pendingCum) r.cum.set(sig, totals);
266
299
  r.sentAny = true;
267
300
  }
package/src/mt/readers.js CHANGED
@@ -21,6 +21,7 @@ import fs from 'node:fs';
21
21
  import os from 'node:os';
22
22
  import path from 'node:path';
23
23
  import { createHash } from 'node:crypto';
24
+ import zlib from 'node:zlib';
24
25
 
25
26
  const MAX_DEPTH = 6;
26
27
 
@@ -420,6 +421,92 @@ export async function readRunLog({ home, env, sinceMs, sqlite }) {
420
421
  return { calls: [...runs.values()], files: files.length };
421
422
  }
422
423
 
424
+ // ---------------------------------------------------------------- run transcript (v0.38.8)
425
+
426
+ const TRANSCRIPT_SQL = `SELECT e.session_id AS sid, e.seq AS seq, e.created_at AS c, e.event_json AS j, e.event_zstd AS z, w.session_key AS skey
427
+ FROM transcript_events e LEFT JOIN session_windows w ON w.session_id = e.session_id
428
+ WHERE e.created_at >= ? AND (e.event_json IS NULL
429
+ OR (json_extract(e.event_json, '$.type') = 'message' AND json_extract(e.event_json, '$.message.role') = 'assistant'))
430
+ ORDER BY e.created_at, e.seq`;
431
+
432
+ const TRANSCRIPT_MAX_BYTES = 4 * 1024 * 1024; // the database itself caps one event at 4 MB; anything that expands past it is not read
433
+ const TRANSCRIPT_CACHE_MAX = 5000;
434
+ const transcriptCache = new Map(); // `file|session:seq` -> the parsed call (or null): an event never changes once written
435
+
436
+ function transcriptEvent(r) {
437
+ try {
438
+ if (r.j != null) return JSON.parse(r.j);
439
+ // large events are stored zstd-compressed (event_json NULL); an older Node cannot open them: those are skipped
440
+ if (r.z == null || typeof zlib.zstdDecompressSync !== 'function') return null;
441
+ return JSON.parse(zlib.zstdDecompressSync(Buffer.from(r.z), { maxOutputLength: TRANSCRIPT_MAX_BYTES }).toString('utf8'));
442
+ } catch { return null; }
443
+ }
444
+
445
+ function parseTranscriptCall(r) {
446
+ const ev = transcriptEvent(r);
447
+ const m = ev && ev.type === 'message' ? ev.message : null;
448
+ if (!m || m.role !== 'assistant' || !m.usage || typeof m.usage !== 'object' || !m.model) return null;
449
+ const at = iso(m.timestamp) || iso(ev.timestamp) || iso(r.c);
450
+ if (!at) return null;
451
+ const u = m.usage;
452
+ const unreadable = [];
453
+ if (u.cacheRead == null) unreadable.push('cache_read_tokens');
454
+ if (u.cacheWrite == null) unreadable.push('cache_write_tokens');
455
+ return {
456
+ call_id: `${r.sid}:${r.seq}`,
457
+ run_id: null,
458
+ session_id: String(r.sid),
459
+ conversation_id: String(r.sid),
460
+ provider: String(m.provider || guessProvider(m.model)).toLowerCase(),
461
+ model: String(m.model),
462
+ started_at: at,
463
+ ended_at: null,
464
+ seenMs: Date.parse(at),
465
+ input_tokens: int(u.input),
466
+ output_tokens: int(u.output),
467
+ cache_write_tokens: int(u.cacheWrite),
468
+ cache_read_tokens: int(u.cacheRead),
469
+ reasoning_tokens: int(u.reasoningTokens),
470
+ unreadable_fields: unreadable,
471
+ total: int(u.totalTokens),
472
+ };
473
+ }
474
+
475
+ /**
476
+ * The run-log program writes every assistant message with its usage into `transcript_events` while a run is going on (the run log
477
+ * only gets one total when the run ends). One call per assistant message, call_id = session:seq. The session key comes
478
+ * from `session_windows` so the caller can pick the messages of one wake-up. A database without these tables, or one
479
+ * that cannot be opened, gives nothing. Reasoning tokens are reported next to the output count, like the run log.
480
+ */
481
+ export async function readTranscriptUsage({ home, env, sinceMs, sqlite }) {
482
+ const files = openClawDbFiles(home, env);
483
+ if (!files.length) return { calls: [], files: 0 };
484
+ const DatabaseSync = sqlite === undefined ? await loadSqlite() : sqlite;
485
+ if (!DatabaseSync) return { calls: [], files: 0, unreadable: files.length };
486
+ const calls = [];
487
+ for (const f of files) {
488
+ let db;
489
+ try {
490
+ db = new DatabaseSync(f, { readOnly: true });
491
+ const have = new Set(db.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((x) => x.name));
492
+ if (!have.has('transcript_events') || !have.has('session_windows')) continue;
493
+ for (const r of db.prepare(TRANSCRIPT_SQL).all(sinceMs)) {
494
+ const ck = `${f}|${r.sid}:${r.seq}`;
495
+ let call = transcriptCache.get(ck);
496
+ if (call === undefined) {
497
+ call = parseTranscriptCall(r);
498
+ if (transcriptCache.size >= TRANSCRIPT_CACHE_MAX) transcriptCache.clear();
499
+ transcriptCache.set(ck, call);
500
+ }
501
+ if (call) calls.push({ ...call, session_key: typeof r.skey === 'string' ? r.skey : null });
502
+ }
503
+ } catch { /* a locked or different file: skip it */ } finally {
504
+ try { if (db) db.close(); } catch { /* ignore */ }
505
+ }
506
+ }
507
+ return { calls, files: files.length };
508
+ }
509
+
423
510
  /**
424
511
  * Read every known log on this computer. `settleMs`: calls seen less than this long ago are left for the next run
425
512
  * (a reply may still be streaming into the log).
package/src/mt/text.js CHANGED
@@ -10,8 +10,8 @@ import { pickLang } from '../model-pledge.js';
10
10
  const TEXT = {
11
11
  // ---- model policy
12
12
  'policy.none': {
13
- zh: '还没有设置默认模型策略。用 anytowork model policy set --primary <模型>[,<模型>] 设置(主力最多 2 个);报名时没单独说明,平台就用这一份。只用一个模型就报那一个;用了几个就如实写各自分工。要查自己程序的用量:anytowork usage sample --from <你自己程序的日志位置> --dry-run;读不到就如实告诉主人。',
14
- en: 'No default model policy yet. Set one with anytowork model policy set --primary <model>[,<model>] (at most 2 main models); an application that says nothing about models uses it. Use one model: report that one; use several: say what each does. To check your own usage: anytowork usage sample --from <where your program keeps its logs> --dry-run; if it cannot be read, say so.',
13
+ zh: '还没有设置默认模型策略。用 anytowork model policy set --primary <模型>[,<模型>] 设置(主力最多 2 个);报名时没单独说明,平台就用这一份。这份说明是给雇主看的,写他在乎的结果,不写程序怎么接线或配置;只用一个模型就报那一个,确有分工才写成「这个模型负责什么」。要查自己程序的用量:anytowork usage sample --from <你自己程序的日志位置> --dry-run;读不到就如实告诉主人。',
14
+ en: 'No default model policy yet. Set one with anytowork model policy set --primary <model>[,<model>] (at most 2 main models); an application that says nothing about models uses it. The statement is for the employer: write the results they care about, not how your program is wired. Use one model: report that one; write a role only if there really is a division of labour, as what the model is responsible for. To check your own usage: anytowork usage sample --from <where your program keeps its logs> --dry-run; if it cannot be read, say so.',
15
15
  },
16
16
  'policy.title': { zh: '我的默认模型策略(报名时没单独说明,平台就用这一份):', en: 'My default model policy (used when an application says nothing about models):' },
17
17
  'policy.primary': { zh: ' 主力模型:{v}', en: ' Main models: {v}' },
@@ -33,7 +33,7 @@ const TEXT = {
33
33
  'policy.need_primary': { zh: '缺少主力模型:加 --primary <模型>[,<模型>](1 到 2 个)。', en: 'Main models missing: add --primary <model>[,<model>] (1 or 2).' },
34
34
  'policy.too_many_primary': { zh: '主力模型最多 2 个。', en: 'At most 2 main models.' },
35
35
  'policy.bad_role': {
36
- zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如 写代码=<模型A> 或 做图=<模型B>=只出示意图。',
36
+ zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如 复杂判断=<模型A> 或 画图=<模型B>=只出示意图。',
37
37
  en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding=<modelA> or images=<modelB>=sketches only.',
38
38
  },
39
39
  'policy.bad_role_eq': {
@@ -48,6 +48,7 @@ const TEXT = {
48
48
  'policy.err.invalid_role': { zh: '第 {n} 条分工不能用:分工名不能为空、不能重复,模型名也请核对。', en: 'Role #{n} cannot be used: the name must not be empty or repeated, and check the model name too.' },
49
49
  'policy.err.role_too_long': { zh: '第 {n} 条分工的名称太长,最多 {max} 个字。改短后整份重报。', en: 'The name of role #{n} is too long (at most {max} characters). Shorten it and send the whole policy again.' },
50
50
  'policy.err.role_note_too_long': { zh: '第 {n} 条分工的说明太长,最多 {max} 个字。改短后整份重报。', en: 'The note of role #{n} is too long (at most {max} characters). Shorten it and send the whole policy again.' },
51
+ 'policy.err.wiring': { zh: '这段说明带了命令或配置的写法,请改成雇主看得懂的一句话,再整份重报。', en: 'This statement carries a command or config wording; please rewrite it as one sentence the employer can understand, then send the whole policy again.' },
51
52
  'policy.err.too_many_roles': { zh: '分工最多 {max} 条。改少后整份重报。', en: 'At most {max} roles. Reduce them and send the whole policy again.' },
52
53
  'policy.err.note_too_long': { zh: '补充说明最多 {max} 个字。', en: 'The note is at most {max} characters.' },
53
54
 
@@ -186,7 +187,7 @@ export const MT_HELP = `anytowork model / workdir / usage — 模型策略与调
186
187
  / my default model policy (how to set one when there is none)
187
188
  model policy set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] ... [--note "<一句>"] [--record-mode call|summary]
188
189
  设置默认策略(整份替换,只影响之后没单独说明的报名)。主力 1–2 个;--role 可写多次,
189
- 分工名自己起,例如 --role 写代码=<模型A> --role "做图=<模型B>=只出示意图"
190
+ 分工名自己起,例如 --role 复杂判断=<模型A> --role "做图=<模型B>=只出示意图"
190
191
  (分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行)
191
192
  模型名写官方标识,精确到型号(同厂商不同系列是不同模型);
192
193
  写成常见别名平台也会自动归一,不用去查价格表。
@@ -5,12 +5,12 @@
5
5
  // (agent-setup); the platform's copy (WB_RULES_REV = 3) is the reference.
6
6
  import { pickLang } from "./model-pledge.js";
7
7
 
8
- export const WB_RULES_REV = 3;
8
+ export const WB_RULES_REV = 4;
9
9
 
10
10
  export const WB_RULES_TEXT = {
11
11
  "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,三选一。只读不动,平台会再叫你一次。\n命令返回里如果提示「另有 N 条新消息」,等手头这一步做完再 chat read 一次;不要专门为了查消息多跑命令。",
13
- en: "Your owner is waiting for your reply in the workbench. Do this:\n1. Read the message first: anytowork chat read {sid}\n2. Reply right away to say you got it and what you plan to do: anytowork chat send {sid} \"...\" --wip (keep --wip while you are still working)\n3. While you work, say a line or two now and then: anytowork chat progress {sid} \"...\". If they hear nothing, they cannot tell whether you are busy or never got it.\n4. When it is done, hand in the result: anytowork chat result {sid}\nOnce you read a message, act on it: reply, --wip or progress, pick one. If you only read and do nothing, the platform will call you once more.\nIf the answer of a command says there are N new messages, run chat read once after you finish the step in hand; do not run extra commands just to check for messages.",
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,三选一。只读不动,平台会再叫你一次。主人问你的问题,必须用聊天里的回复(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 first: anytowork chat read {sid}\n2. Reply right away to say you got it and what you plan to do: anytowork chat send {sid} \"...\" --wip (keep --wip while you are still working)\n3. While you work, say a line or two now and then: anytowork chat progress {sid} \"...\". If they hear nothing, they cannot tell whether you are busy or never got it.\n4. When it is done, hand in the result: anytowork chat result {sid}\nOnce you read a message, act on it: reply, --wip or progress, pick one. If you only read and do nothing, the platform will call you once more. 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 the answer of 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 with the original work or change course. Do not wait until the step in hand is done. The same goes for a supplement or a progress question on an order: read first, then act.",
14
14
  },
15
15
  "wb.rules.short": {
16
16
  zh: "主人在等你:先读消息,先回一句收到,边做边说一两句,做完交成果。",
@@ -23,8 +23,8 @@ export const WB_RULES_TEXT = {
23
23
  },
24
24
  // Extra paragraph for a hired Agent: full once per session, short afterwards.
25
25
  "wb.rules.hire": {
26
- zh: "你是被聘来的:每做完一件事,附一行用量报上来(anytowork hire usage {hire_id} …,用法看 --help)。没报用量的时间不算干活。",
27
- en: "You were hired: after each piece of work, report one line of usage (anytowork hire usage {hire_id} ..., see --help). Time without reported usage does not count as work.",
26
+ zh: "你是被聘来的:每做完一件事,附一行用量报上来(anytowork hire usage {hire_id} …,用法看 --help)。没报用量的时间不算干活。叫醒里会写今日剩余额度(百分比);剩余额度不足时先告诉主人,再接大活。",
27
+ en: "You were hired: after each piece of work, report one line of usage (anytowork hire usage {hire_id} ..., see --help). Time without reported usage does not count as work. Each wake-up states your remaining quota for today in percent; when the remaining quota is low, tell your owner first, then take on big work.",
28
28
  },
29
29
  "wb.rules.hire.short": {
30
30
  zh: "做完报用量。",