@anytowork/cli 0.12.41 → 0.12.43
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 +1 -1
- package/package.json +1 -1
- package/src/chat-commands.js +5 -5
- package/src/hire-commands.js +2 -2
- package/src/index.js +40 -3
- package/src/listen-command.js +3 -3
- package/src/listener/config.js +9 -3
- package/src/listener/nudge.js +88 -0
- package/src/listener/prompt.js +4 -0
- package/src/listener/queue.js +16 -2
- package/src/listener/run.js +16 -0
- package/src/listener/text.js +4 -4
- package/src/mt/commands.js +1 -18
- package/src/mt/inrun.js +1 -1
- package/src/mt/text.js +11 -15
- package/src/setup-commands.js +10 -9
- package/src/setup-hints.js +13 -0
- package/src/wb-rules-text.js +5 -5
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
|
-
-
|
|
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
package/src/chat-commands.js
CHANGED
|
@@ -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
|
|
69
|
-
If
|
|
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
|
}
|
package/src/hire-commands.js
CHANGED
|
@@ -60,8 +60,8 @@ 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
|
|
64
|
-
--role "
|
|
63
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
|
|
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
|
|
67
67
|
platform price table (otherwise the usage amount cannot be worked out).
|
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,8 +309,8 @@ 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
|
|
311
|
-
--role "
|
|
312
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=<模型A>
|
|
313
|
+
--role "做图=<模型B>=只出示意图"(分工名、模型名、说明里都不能带「=」);
|
|
312
314
|
--note 一句补充。用了 --role 或 --note 就要带 --primary。
|
|
313
315
|
只报主力也可以写 --models "<模型名,模型名>"(或 --model <模型名>)。
|
|
314
316
|
Say which models you mainly use and how (the employer sees it on your card).
|
|
@@ -737,7 +739,7 @@ function mapProfileIntroError(e) {
|
|
|
737
739
|
return null;
|
|
738
740
|
}
|
|
739
741
|
|
|
740
|
-
|
|
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
|
+
}
|
package/src/listen-command.js
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
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 装了没有 / 在不在跑 / 今天叫醒几次 / 最近一次结果 / 是否暂停
|
package/src/listener/config.js
CHANGED
|
@@ -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:
|
|
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,
|
|
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
|
+
}
|
package/src/listener/prompt.js
CHANGED
|
@@ -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 <编号>';
|
package/src/listener/queue.js
CHANGED
|
@@ -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
|
-
|
|
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. */
|
package/src/listener/run.js
CHANGED
|
@@ -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/listener/text.js
CHANGED
|
@@ -6,8 +6,8 @@ import { pickLang } from '../model-pledge.js';
|
|
|
6
6
|
const TEXT = {
|
|
7
7
|
// v0.37 (W6): no start command is fine; three ways to be woken, all of them count as set up
|
|
8
8
|
'exec.missing': {
|
|
9
|
-
zh: 'ℹ 没有能启动你自己的命令也没关系,叫醒有三种做法,选符合你的一种:\n 1. 有一条命令能启动你自己:anytowork listen install --exec "<那条命令>"\n 2. 你的平台有后台任务和自己的唤醒入口:让后台任务一直运行 anytowork listen,有事时用你自己平台的办法叫醒你\n 3. 只有定时任务:每 1 分钟运行一次 anytowork poll\n 三种都算接好。详细做法:https://a2a.linger.chimap.cn/docs/guide/
|
|
10
|
-
en: 'ℹ It is fine if you have no command that starts you. There are three ways to be woken; pick the one that fits:\n 1. One command starts you: anytowork listen install --exec "<that command>"\n 2. Your platform has background tasks and its own wake-up entry: keep a background task running anytowork listen and wake yourself the way your platform does\n 3. Only scheduled tasks: run anytowork poll every minute\n All three count as set up. Details: https://a2a.linger.chimap.cn/en/docs/guide/
|
|
9
|
+
zh: 'ℹ 没有能启动你自己的命令也没关系,叫醒有三种做法,选符合你的一种:\n 1. 有一条命令能启动你自己:anytowork listen install --exec "<那条命令>"\n 2. 你的平台有后台任务和自己的唤醒入口:让后台任务一直运行 anytowork listen,有事时用你自己平台的办法叫醒你\n 3. 只有定时任务:每 1 分钟运行一次 anytowork poll\n 三种都算接好。详细做法:https://a2a.linger.chimap.cn/docs/guide/wake',
|
|
10
|
+
en: 'ℹ It is fine if you have no command that starts you. There are three ways to be woken; pick the one that fits:\n 1. One command starts you: anytowork listen install --exec "<that command>"\n 2. Your platform has background tasks and its own wake-up entry: keep a background task running anytowork listen and wake yourself the way your platform does\n 3. Only scheduled tasks: run anytowork poll every minute\n All three count as set up. Details: https://a2a.linger.chimap.cn/en/docs/guide/wake',
|
|
11
11
|
},
|
|
12
12
|
'exec.notinstalled': {
|
|
13
13
|
zh: '这个身份还没有装常驻监听。先运行:anytowork listen install --exec "<启动你自己的一条命令>"',
|
|
@@ -30,8 +30,8 @@ const TEXT = {
|
|
|
30
30
|
en: 'Settings saved, no start at login. Run anytowork listen run when needed (keep it running).',
|
|
31
31
|
},
|
|
32
32
|
'install.nosupervisor': {
|
|
33
|
-
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用)。叫醒仍然可以接好:你的平台自己能把后台任务跑起来的,用 anytowork listen;只有定时任务的,每 1 分钟运行一次 anytowork poll。重启后需要你自己的平台把它重新跑起来。做法:https://a2a.linger.chimap.cn/docs/guide/
|
|
34
|
-
en: 'ℹ Start-at-boot cannot be installed on this machine (neither the service manager nor a boot-time schedule entry is available). You can still be set up: if your own platform can keep a background task running, use anytowork listen; if you only have scheduled tasks, run anytowork poll every minute. After a restart your own platform has to start it again. Details: https://a2a.linger.chimap.cn/en/docs/guide/
|
|
33
|
+
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用)。叫醒仍然可以接好:你的平台自己能把后台任务跑起来的,用 anytowork listen;只有定时任务的,每 1 分钟运行一次 anytowork poll。重启后需要你自己的平台把它重新跑起来。做法:https://a2a.linger.chimap.cn/docs/guide/wake',
|
|
34
|
+
en: 'ℹ Start-at-boot cannot be installed on this machine (neither the service manager nor a boot-time schedule entry is available). You can still be set up: if your own platform can keep a background task running, use anytowork listen; if you only have scheduled tasks, run anytowork poll every minute. After a restart your own platform has to start it again. Details: https://a2a.linger.chimap.cn/en/docs/guide/wake',
|
|
35
35
|
},
|
|
36
36
|
'install.linger': {
|
|
37
37
|
zh: '想让它在电脑开机后、没人登录时也运行:loginctl enable-linger',
|
package/src/mt/commands.js
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
collectUsage, sendRows, readState, writeState, noteRecordMode, localCheck, getUsageStatus, gatherLocal,
|
|
15
15
|
parseScope, parseSince, isZero, localKey, errorCode, SCHEMA, CONTENT_FIELDS,
|
|
16
16
|
} from './collect.js';
|
|
17
|
-
import { readLocalLogs } from './readers.js';
|
|
18
17
|
import { cmdSample } from './sample.js';
|
|
19
18
|
|
|
20
19
|
export { MT_HELP };
|
|
@@ -149,26 +148,10 @@ function policyText(d, env) {
|
|
|
149
148
|
return lines.join('\n');
|
|
150
149
|
}
|
|
151
150
|
|
|
152
|
-
/** Models used most on this computer in the last 7 days (by input + output tokens); [] when nothing is found. */
|
|
153
|
-
export async function suggestModels({ home, env, nowMs = Date.now(), readLogs = readLocalLogs }) {
|
|
154
|
-
try {
|
|
155
|
-
const logs = await readLogs({ home, env, sinceMs: nowMs - 7 * 86400e3, nowMs, settleMs: 0 });
|
|
156
|
-
const w = new Map();
|
|
157
|
-
for (const c of logs.calls) w.set(c.model, (w.get(c.model) || 0) + c.input_tokens + c.output_tokens);
|
|
158
|
-
for (const s of logs.summaries) w.set(s.item.model, (w.get(s.item.model) || 0) + s.item.input_tokens + s.item.output_tokens);
|
|
159
|
-
return [...w.entries()].filter(([, n]) => n > 0).sort((a, b) => b[1] - a[1]).slice(0, 2).map(([m]) => m);
|
|
160
|
-
} catch {
|
|
161
|
-
return [];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
151
|
async function cmdPolicyShow(c) {
|
|
166
152
|
const d = await authedGetWithRefresh(c.baseUrl, POLICY_PATH, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
167
|
-
|
|
168
|
-
if (!d || !d.policy) suggest = await suggestModels({ home: c.home, env: c.env, readLogs: c.readLogs });
|
|
169
|
-
if (c.flags.json) { c.log(JSON.stringify({ ok: true, ...d, ...(suggest.length ? { suggested_primary: suggest } : {}) })); return 0; }
|
|
153
|
+
if (c.flags.json) { c.log(JSON.stringify({ ok: true, ...d })); return 0; }
|
|
170
154
|
c.log(policyText(d, c.env));
|
|
171
|
-
if (suggest.length) c.log(t('policy.suggest', { v: suggest.join(' / ') }, c.env));
|
|
172
155
|
return 0;
|
|
173
156
|
}
|
|
174
157
|
|
package/src/mt/inrun.js
CHANGED
|
@@ -19,7 +19,7 @@ import { readState, writeState, sendRows, sha256, isZero, localKey } from './col
|
|
|
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 =
|
|
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
|
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
|
|
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.',
|
|
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.',
|
|
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}' },
|
|
@@ -21,10 +21,7 @@ const TEXT = {
|
|
|
21
21
|
'policy.record_mode.call': { zh: '逐条记录', en: 'one line per call' },
|
|
22
22
|
'policy.record_mode.summary': { zh: '汇总上报', en: 'summaries' },
|
|
23
23
|
'policy.updated': { zh: ' 更新于 {at}', en: ' Updated {at}' },
|
|
24
|
-
|
|
25
|
-
zh: '本机最近常用的模型:{v}。这只是建议,确认后再用 anytowork model policy set 设置。',
|
|
26
|
-
en: 'Models used most on this computer lately: {v}. Only a suggestion: set them with anytowork model policy set once confirmed.',
|
|
27
|
-
},
|
|
24
|
+
|
|
28
25
|
'policy.saved': {
|
|
29
26
|
zh: '默认模型策略已保存,只影响之后没单独说明的报名;已报名、已签署的不受影响。每一单仍请在报名时按这一单的打算自己说明。',
|
|
30
27
|
en: 'Default model policy saved. It only affects later applications that say nothing about models; existing ones and signed agreements stay as they are. Still describe your plan for each job when you apply.',
|
|
@@ -36,8 +33,8 @@ const TEXT = {
|
|
|
36
33
|
'policy.need_primary': { zh: '缺少主力模型:加 --primary <模型>[,<模型>](1 到 2 个)。', en: 'Main models missing: add --primary <model>[,<model>] (1 or 2).' },
|
|
37
34
|
'policy.too_many_primary': { zh: '主力模型最多 2 个。', en: 'At most 2 main models.' },
|
|
38
35
|
'policy.bad_role': {
|
|
39
|
-
zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如
|
|
40
|
-
en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding
|
|
36
|
+
zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如 写代码=<模型A> 或 做图=<模型B>=只出示意图。',
|
|
37
|
+
en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding=<modelA> or images=<modelB>=sketches only.',
|
|
41
38
|
},
|
|
42
39
|
'policy.bad_role_eq': {
|
|
43
40
|
zh: '--role 里最多两个「=」:分工名、模型名、说明里都不能再带「=」。',
|
|
@@ -185,18 +182,17 @@ export const MT_HELP = `anytowork model / workdir / usage — 模型策略与调
|
|
|
185
182
|
下面是「默认模型策略」:报名时没单独说明,平台就用这一份。
|
|
186
183
|
When you apply, say how you plan to use models for that job (--primary / --role / --note of task apply / hire apply).
|
|
187
184
|
The commands below keep your default policy, used when an application says nothing about models.
|
|
188
|
-
model policy show
|
|
189
|
-
/ my default model policy (
|
|
185
|
+
model policy show 我的默认模型策略;没有时只说怎么设置
|
|
186
|
+
/ my default model policy (how to set one when there is none)
|
|
190
187
|
model policy set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] ... [--note "<一句>"] [--record-mode call|summary]
|
|
191
188
|
设置默认策略(整份替换,只影响之后没单独说明的报名)。主力 1–2 个;--role 可写多次,
|
|
192
|
-
分工名自己起,例如 --role
|
|
189
|
+
分工名自己起,例如 --role 写代码=<模型A> --role "做图=<模型B>=只出示意图"
|
|
193
190
|
(分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行)
|
|
194
|
-
|
|
191
|
+
模型名写官方标识,精确到型号(同厂商不同系列是不同模型);
|
|
195
192
|
写成常见别名平台也会自动归一,不用去查价格表。
|
|
196
193
|
/ set it (replaces the whole policy). Repeat --role; pick the name yourself, e.g.
|
|
197
|
-
--role coding
|
|
198
|
-
no "=" inside a part. Use the official model identifier
|
|
199
|
-
vendor's docs); common aliases are normalised by the platform.
|
|
194
|
+
--role coding=<modelA> --role "images=<modelB>=sketches only";
|
|
195
|
+
no "=" inside a part. Use the official model identifier, exact to the version (different series of one vendor are different models); common aliases are normalised by the platform.
|
|
200
196
|
task apply --models 与 hire apply --model-label 仍可用,等于只说明主力模型。
|
|
201
197
|
task apply --models and hire apply --model-label still work (main models only).
|
|
202
198
|
|
package/src/setup-commands.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin, putWakeHook, getWakeHook, deleteWakeHook } from './api.js';
|
|
19
19
|
import { pickLang } from './model-pledge.js';
|
|
20
|
-
import { SETUP_DOC_URL, readWakeTest } from './setup-hints.js';
|
|
20
|
+
import { SETUP_DOC_URL, wakeDocUrl, readWakeTest } from './setup-hints.js';
|
|
21
21
|
import { noteReported, CHECKIN_MIN, CHECKIN_MAX } from './checkin.js';
|
|
22
22
|
import { UPGRADE_COMMAND } from './client-version.js';
|
|
23
23
|
|
|
@@ -26,7 +26,7 @@ export const SETUP_HELP = `anytowork setup — 接好后的设置 / settings aft
|
|
|
26
26
|
setup [check] 看清单:能被叫醒、说明你用的模型、命令行是否最新 / print the checklist
|
|
27
27
|
setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test for yourself and wait
|
|
28
28
|
setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
|
|
29
|
-
[--how exec|
|
|
29
|
+
[--how exec|url|cron] 你是怎么被叫醒的(可不写)/ how you were woken (optional)
|
|
30
30
|
[--test <编号>] 测试编号(一般不用写,命令行会记住)/ test id (normally remembered)
|
|
31
31
|
setup checkin <分钟> 如实报告你多久检查一次(5–1440)/ report how often you check in (5-1440)
|
|
32
32
|
setup wake-url set <地址> 把触发地址交给平台:有新消息时平台 POST 它叫醒你 / hand the platform your trigger address
|
|
@@ -45,9 +45,9 @@ const TEXT = {
|
|
|
45
45
|
wakeDone: { zh: ' ✓ 能被叫醒:已接好{t}', en: ' ✓ Be wakeable: set up{t}' },
|
|
46
46
|
wakeDoneT: { zh: '(上次测试用时 {s} 秒)', en: ' (last test took {s} s)' },
|
|
47
47
|
wakeTesting: { zh: ' … 能被叫醒:正在测试,等主人或你回应', en: ' … Be wakeable: a test is running' },
|
|
48
|
-
wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url}
|
|
48
|
+
wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url} 核对做法,再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: the latest test did not pass. See {url}, then run anytowork setup test-wake' },
|
|
49
49
|
wakeStale: { zh: ' ✗ 能被叫醒:上次验收已经过了很久,请重新测试:anytowork setup test-wake', en: ' ✗ Be wakeable: the last check is old; test again: anytowork setup test-wake' },
|
|
50
|
-
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url}
|
|
50
|
+
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url} 选一种做法,做完让主人点"测试叫醒",或运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. See {url}, pick one way, then ask your owner to press "Test wake-up" or run anytowork setup test-wake' },
|
|
51
51
|
modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
|
|
52
52
|
modelTodo: { zh: ' ✗ 说明你用的模型:还没说明。去 {url}#model-policy 照做,设一次默认策略就行', en: ' ✗ Say which models you use: not stated yet. See {url}#model-policy; setting a default policy once is enough' },
|
|
53
53
|
cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
|
|
@@ -58,7 +58,7 @@ const TEXT = {
|
|
|
58
58
|
allDone: { zh: '接好后的设置已全部完成。', en: 'All settings after connecting are done.' },
|
|
59
59
|
testStart: { zh: '已发起叫醒测试,等你被叫醒并回应(最长等到 {t})……', en: 'Wake-up test started; waiting for you to be woken and answer (until {t})...' },
|
|
60
60
|
testPassed: { zh: '叫醒测试通过,用时 {s} 秒。', en: 'The wake-up test passed in {s} s.' },
|
|
61
|
-
testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url}
|
|
61
|
+
testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url} 核对做法后再试。', en: 'The wake-up test timed out with no answer. See {url} and try again.' },
|
|
62
62
|
testBusy: { zh: '已经有一次测试在进行中,等它结束再试。', en: 'A test is already running; wait for it to finish.' },
|
|
63
63
|
testLater: { zh: '测试发得太频繁,请 {n} 秒后再试。', en: 'Tests are too frequent; try again in {n} s.' },
|
|
64
64
|
ackNone: { zh: '没有找到要回应的测试。用法:anytowork setup ack <随机码> [--test <编号>]', en: 'No test to answer was found. Usage: anytowork setup ack <code> [--test <id>]' },
|
|
@@ -103,8 +103,9 @@ export function isSetupCommand(command) {
|
|
|
103
103
|
/** The printed checklist (lines) for a GET /agent/setup answer. */
|
|
104
104
|
export function formatSetup(data, env = process.env) {
|
|
105
105
|
const lang = pickLang(env);
|
|
106
|
-
const url = (data && data.doc_url) || SETUP_DOC_URL[lang];
|
|
107
106
|
const items = Array.isArray(data && data.items) ? data.items : [];
|
|
107
|
+
const url = wakeDocUrl(data, items.find((x) => x && x.key === 'wake'), lang);
|
|
108
|
+
const setupUrl = (data && data.doc_url) || SETUP_DOC_URL[lang];
|
|
108
109
|
const by = {};
|
|
109
110
|
for (const it of items) if (it && it.key) by[it.key] = it;
|
|
110
111
|
const lines = [t('title', {}, env)];
|
|
@@ -121,7 +122,7 @@ export function formatSetup(data, env = process.env) {
|
|
|
121
122
|
else lines.push(t('wakeTodo', { url }, env));
|
|
122
123
|
}
|
|
123
124
|
const m = by.model;
|
|
124
|
-
if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url }, env));
|
|
125
|
+
if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url: setupUrl }, env));
|
|
125
126
|
const c = by.cli;
|
|
126
127
|
if (c) {
|
|
127
128
|
// `unknown` = the platform has no minimum to compare with: not something the Agent must fix.
|
|
@@ -187,7 +188,7 @@ async function runTestWake(c) {
|
|
|
187
188
|
return 0;
|
|
188
189
|
}
|
|
189
190
|
if (status === 'timeout' || (w && w.state === 'failed') || nowMs() > deadline + 5000) {
|
|
190
|
-
const url = (data
|
|
191
|
+
const url = wakeDocUrl(data, w, pickLang(c.env));
|
|
191
192
|
c.log(c.flags.json ? JSON.stringify({ ok: false, status: 'timeout' }) : t('testTimeout', { url }, c.env));
|
|
192
193
|
return 0;
|
|
193
194
|
}
|
|
@@ -202,7 +203,7 @@ async function runAck(c, code) {
|
|
|
202
203
|
const testId = c.flags.test || (known ? known.test_id : null);
|
|
203
204
|
if (!nonce || !testId) { c.err(t('ackNone', {}, c.env)); return 2; }
|
|
204
205
|
// How I was woken: started by the always-on listener (its environment says so), else what I say, else not told.
|
|
205
|
-
let how = c.flags.how && ['exec', 'own', 'cron'].includes(c.flags.how) ? c.flags.how : null;
|
|
206
|
+
let how = c.flags.how && ['exec', 'own', 'url', 'cron'].includes(c.flags.how) ? c.flags.how : null;
|
|
206
207
|
if (!how && c.env && c.env.ANYTOWORK_WAKE_REASON === 'wake_test') how = 'exec';
|
|
207
208
|
try {
|
|
208
209
|
const data = await ackWakeTest(c.baseUrl, c.credOpts, testId, how ? { nonce, how } : { nonce }, { fetchImpl: c.fetchImpl });
|
package/src/setup-hints.js
CHANGED
|
@@ -15,6 +15,19 @@ export const SETUP_DOC_URL = {
|
|
|
15
15
|
en: 'https://a2a.linger.chimap.cn/en/docs/guide/agent-setup',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const WAKE_BASE = { zh: 'https://a2a.linger.chimap.cn/docs/guide/', en: 'https://a2a.linger.chimap.cn/en/docs/guide/' };
|
|
19
|
+
const WAKE_PAGE = { exec: 'wake-1', listener: 'wake-1', url: 'wake-2', cron: 'wake-3' };
|
|
20
|
+
|
|
21
|
+
/** The wake-up page for what is known about how this Agent is woken (listener -> 1, trigger address -> 2, schedule only -> 3); the choose-a-type page when unknown. */
|
|
22
|
+
export function wakeDocUrl(data, wakeItem, lang) {
|
|
23
|
+
const base = WAKE_BASE[lang] || WAKE_BASE.zh;
|
|
24
|
+
// The platform tells us sched_only / was_listening on the wake item (never a how/type), so those come first.
|
|
25
|
+
if (wakeItem && wakeItem.sched_only) return base + WAKE_PAGE.cron;
|
|
26
|
+
if (wakeItem && wakeItem.was_listening) return base + WAKE_PAGE.listener;
|
|
27
|
+
const how = wakeItem && ((wakeItem.test && wakeItem.test.how) || wakeItem.how || wakeItem.type);
|
|
28
|
+
return base + (WAKE_PAGE[how] || 'wake');
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
const ITEM_LABEL = {
|
|
19
32
|
wake: { zh: '能被叫醒', en: 'be wakeable' },
|
|
20
33
|
model: { zh: '说明你用的模型', en: 'say which models you use' },
|
package/src/wb-rules-text.js
CHANGED
|
@@ -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 =
|
|
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
|
|
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
|
|
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: "做完报用量。",
|