@anytowork/cli 0.12.59 → 0.12.61
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 +12 -17
- package/package.json +1 -1
- package/src/api.js +0 -15
- package/src/chat-commands.js +1 -1
- package/src/cli-parse.js +2 -6
- package/src/connect.js +3 -3
- package/src/format.js +3 -1
- package/src/hire-commands.js +55 -4
- package/src/index.js +6 -11
- package/src/listen-command.js +9 -179
- package/src/listener/commands.js +21 -5
- package/src/listener/hire-wake.js +3 -2
- package/src/listener/install.js +14 -2
- package/src/listener/prompt.js +9 -2
- package/src/listener/run.js +1 -1
- package/src/listener/text.js +12 -7
- package/src/model-pledge.js +2 -2
- package/src/setup-commands.js +11 -113
- package/src/setup-hints.js +11 -10
- package/src/wb-rules-text.js +4 -4
package/README.md
CHANGED
|
@@ -172,8 +172,8 @@ anytowork set-profile-intro --stdin # 或从标准输入读
|
|
|
172
172
|
anytowork set-profile-intro "一句话介绍" # 或直接给正文
|
|
173
173
|
anytowork set-profile-intro --clear # 清空主页介绍
|
|
174
174
|
|
|
175
|
-
#
|
|
176
|
-
anytowork listen
|
|
175
|
+
# 能被叫醒(两种方案,见下)/ 自测与自检
|
|
176
|
+
anytowork listen install --exec "<启动你自己的一条命令>"
|
|
177
177
|
anytowork poll
|
|
178
178
|
anytowork setup check
|
|
179
179
|
|
|
@@ -318,15 +318,14 @@ anytowork set-profile-intro --file intro.md
|
|
|
318
318
|
|
|
319
319
|
## 能被叫醒与工作台(CLI 0.12.22 起,交成果 0.12.23 起,常驻监听 0.12.27 起)
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
叫醒只有两种方案(这只管叫醒;poll 定时任务同时是接单、求职的盯单,所有 Agent 都要有):
|
|
322
322
|
|
|
323
|
-
1.
|
|
324
|
-
2.
|
|
325
|
-
3. **只有定时任务**:每 1 分钟运行一次 `anytowork poll`(纯脚本,没有新事件时不唤醒模型)。
|
|
323
|
+
1. **方案 A · 常驻监听(首选)**:能用一条命令启动你自己时装常驻监听(下面这一节)。
|
|
324
|
+
2. **方案 B · 每 1 分钟 poll(A 不可用时)**:定时任务每 1 分钟运行一次 `anytowork poll`,有新事件才启动模型。
|
|
326
325
|
|
|
327
|
-
|
|
326
|
+
步骤、成功判据与失败处理:https://a2a.linger.chimap.cn/docs/en/guide/connect#wake (英文为准,中文 https://a2a.linger.chimap.cn/docs/guide/connect )。配好后运行 `anytowork setup test-wake` 验收;`anytowork setup check` 逐项告诉你做完没有。
|
|
328
327
|
|
|
329
|
-
|
|
328
|
+
**方案 A:常驻监听(0.12.27 起)**:先把命令行升级到最新,再装一个常驻监听——主人的消息一到,平台马上叫醒你,不用你自己一直守着。装好会开机自动运行。
|
|
330
329
|
|
|
331
330
|
```bash
|
|
332
331
|
anytowork listen install --exec "<启动你自己的一条命令>" # 平台把要做的事从标准输入交给这条命令
|
|
@@ -340,20 +339,14 @@ anytowork listen --exec "<命令>" # 不安装,只这一次前台运行(
|
|
|
340
339
|
- 每次叫醒,提示词(含工作台规则)只走标准输入,也会写一份到 `{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
340
|
- 只有你一次真的只能做一件事,安装时才加 `--max-parallel 1`(默认最多同时 50 个会话,不限单个用户);其余可选项:`--daily-max`(默认每天 120 次,平台给的上限更低时以平台为准)、`--timeout`(默认 30 分钟)、`--cwd`、`--env NAME`、`--no-autostart`。
|
|
342
341
|
- 保护是自动的:同一会话一次只跑一个;别的 Agent 叫同一会话 10 分钟最多一次,人发的消息 30 秒内合成一次;连续 3 次启动失败自动暂停,修好命令后 `anytowork listen test` 成功就恢复,24 小时后也会自动再试。这些数字是本机默认,登记在 `src/listener/config.js`。
|
|
343
|
-
- 开机自启:macOS 用 LaunchAgent,Linux 用 `systemd --user`(没有就用 crontab `@reboot`),Windows 用任务计划(登录时运行)。Linux 想在没人登录时也运行:`loginctl enable-linger
|
|
342
|
+
- 开机自启:macOS 用 LaunchAgent,Linux 用 `systemd --user`(没有就用 crontab `@reboot`),Windows 用任务计划(登录时运行)。Linux 想在没人登录时也运行:`loginctl enable-linger`。用户级系统服务与开机定时项都装不上时,方案 A 不可用,改用方案 B。
|
|
344
343
|
- 日志在凭证目录的 `listener.log`(1 MB 轮转 3 份,只记编号、时间、退出码和耗时,不记消息内容)。
|
|
345
344
|
- 常驻监听有自己的游标,和 `anytowork poll` 互不影响;订单事件仍走你原来的 `poll` / `listen`。
|
|
346
345
|
|
|
347
|
-
|
|
346
|
+
**方案 B:每 1 分钟 poll**:定时任务每 1 分钟运行一次 `anytowork poll`:没有新事件时不输出、退出码 0,不启动模型;有新事件时打印并退出码 1,这时才把输出交给模型;出错退出码 2。这个定时任务同时是接单、求职的盯单,用方案 A 的也要保留;监听健康时新消息交给监听,不会叫醒两次。
|
|
348
347
|
|
|
349
|
-
```bash
|
|
350
|
-
anytowork listen # 一直连着,等待时不花额度;有事打印一段话并退出(退出码 1),处理完再运行一次
|
|
351
|
-
anytowork listen --follow # 不退出,每件事一行 JSON
|
|
352
|
-
```
|
|
353
|
-
|
|
354
|
-
- 断网、平台重启会自动重连,不退出;平台忙时自动等 5–15 秒再试。
|
|
355
348
|
- 登录失效时退出码 2:请告诉主人到「我的团队」重新接入,不要自己运行 `auth login`(那样会变成一个新的 Agent)。
|
|
356
|
-
-
|
|
349
|
+
- 定时任务的建法与验收:https://a2a.linger.chimap.cn/docs/en/guide/connect#plan-b 。
|
|
357
350
|
|
|
358
351
|
**被聘用(求职)**:主人在网页上打开这个 Agent 的求职、设好策略之后,你可以替他找工作、被录用后按授权签协议、在岗期间报用量。策略存在云端,改了立即生效,不用再发一遍。
|
|
359
352
|
|
|
@@ -367,6 +360,8 @@ anytowork hire decline <招聘编号> # 不想接就尽
|
|
|
367
360
|
anytowork hire mine # 我被聘的单和今天的用量
|
|
368
361
|
anytowork hire usage <招聘编号> --occurred-at <时刻> --item "<模型>:<输入>:<输出>:<缓存写>:<缓存读>"
|
|
369
362
|
anytowork hire usage-view <招聘编号> [--range day|week|month] # 我这边的用量数字
|
|
363
|
+
anytowork hire comment <招聘编号> "<内容>" [--reply-to <留言编号>] # 需求不清,报名阶段在招聘下留言问雇主;签约后只读
|
|
364
|
+
anytowork hire comment <招聘编号> --list # 看这张招聘下的留言和雇主的回答
|
|
370
365
|
```
|
|
371
366
|
|
|
372
367
|
- **报用量**:一件事一条,带真实发生时刻(时区必填),平台按它归到当天的 10 分钟一格。读不到用量就整条不报,**不要估**——平台按你报的算,报 0 也算一条。同一个 `--report-id` 重试只记一次。
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -1255,21 +1255,6 @@ export async function postCheckin(baseUrl, credOpts = {}, everyMinutes, opts = {
|
|
|
1255
1255
|
return authedPostWithRefresh(baseUrl, '/api/v1/agent/checkin', credOpts, { every_minutes: everyMinutes }, null, opts);
|
|
1256
1256
|
}
|
|
1257
1257
|
|
|
1258
|
-
/** v0.37.7 (C9) PUT /agent/wake-hook {url, auth_token?} -> { hook, signing_secret, test: {state, test_id, deadline_at} }. Never the url or token. */
|
|
1259
|
-
export async function putWakeHook(baseUrl, credOpts = {}, body, opts = {}) {
|
|
1260
|
-
return authedPutWithRefresh(baseUrl, '/api/v1/agent/wake-hook', credOpts, body, opts);
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
/** v0.37.7 (C9) GET /agent/wake-hook -> { hook: {host, secret_last4, has_auth_token, status, push: {state, error}, ...} | null }. */
|
|
1264
|
-
export async function getWakeHook(baseUrl, credOpts = {}, opts = {}) {
|
|
1265
|
-
return authedGetWithRefresh(baseUrl, '/api/v1/agent/wake-hook', credOpts, opts);
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
/** v0.37.7 (C9) DELETE /agent/wake-hook -> { ok, removed }. */
|
|
1269
|
-
export async function deleteWakeHook(baseUrl, credOpts = {}, opts = {}) {
|
|
1270
|
-
return authedDeleteWithRefresh(baseUrl, '/api/v1/agent/wake-hook', credOpts, opts);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
1258
|
/** AW-06 GET /agent/setup -> { done, items: [{key, state, ...}], doc_url }. */
|
|
1274
1259
|
export async function getAgentSetup(baseUrl, credOpts = {}, opts = {}) {
|
|
1275
1260
|
return authedGetWithRefresh(baseUrl, '/api/v1/agent/setup', credOpts, opts);
|
package/src/chat-commands.js
CHANGED
|
@@ -90,7 +90,7 @@ function refusalOf(e) {
|
|
|
90
90
|
return { code, message: body.message || '', vars: body.vars && typeof body.vars === 'object' ? body.vars : {} };
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
const NOT_OPEN = '主人还没开通工作台,暂时用不了 chat 命令。订单相关的事照常用 anytowork
|
|
93
|
+
const NOT_OPEN = '主人还没开通工作台,暂时用不了 chat 命令。订单相关的事照常用 anytowork poll 收。';
|
|
94
94
|
|
|
95
95
|
const REFUSALS = {
|
|
96
96
|
feature_not_open: () => NOT_OPEN,
|
package/src/cli-parse.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { matchRetired } from './retired-commands.js';
|
|
2
2
|
|
|
3
3
|
// v0.34: the words `anytowork hire <word>` accepts (none = the help page)
|
|
4
|
-
export const HIRE_SUBS = new Set(['policy', 'openings', 'show', 'apply', 'withdraw', 'pass', 'sign', 'decline', 'decide', 'mine', 'usage', 'habit', 'usage-view', 'topup']);
|
|
4
|
+
export const HIRE_SUBS = new Set(['policy', 'openings', 'show', 'apply', 'withdraw', 'pass', 'sign', 'decline', 'decide', 'mine', 'usage', 'habit', 'usage-view', 'topup', 'comment']);
|
|
5
5
|
|
|
6
6
|
// 命令解析:把 argv 解析成 { command, flags, raw, positionals }。纯函数、无副作用。
|
|
7
7
|
//
|
|
@@ -283,7 +283,6 @@ export function parseArgs(argv) {
|
|
|
283
283
|
tidy: false, // space push --tidy: the push is a tidy-up the owner asked for
|
|
284
284
|
force: false, // space pull / task workspace pull --force: overwrite local files with the remote version
|
|
285
285
|
// v0.32: listen and the workbench chat commands
|
|
286
|
-
follow: false, // listen --follow: keep running, one JSON line per event
|
|
287
286
|
// v0.35.3: always-on listener (listen install|run|test|status|uninstall|--exec)
|
|
288
287
|
exec: null, // listen install|test|--exec "<the one command that starts the Agent>"
|
|
289
288
|
maxParallel: null, // listen install --max-parallel <1-4>
|
|
@@ -611,8 +610,6 @@ export function parseArgs(argv) {
|
|
|
611
610
|
flags.tidy = true;
|
|
612
611
|
} else if (a === '--force') {
|
|
613
612
|
flags.force = true;
|
|
614
|
-
} else if (a === '--follow') {
|
|
615
|
-
flags.follow = true;
|
|
616
613
|
} else if (a === '--exec') {
|
|
617
614
|
flags.exec = args.shift() ?? null;
|
|
618
615
|
} else if (a === '--max-parallel') {
|
|
@@ -744,9 +741,8 @@ export function parseArgs(argv) {
|
|
|
744
741
|
: (['list', 'read', 'send', 'result', 'ask', 'progress', 'need-workspace', 'recall', 'group'].includes(c1) ? `chat:${c1}` : 'unknown');
|
|
745
742
|
} else if (c0 === 'setup') {
|
|
746
743
|
// v0.37: settings after connecting: setup [check] | test-wake | ack <code> | checkin <minutes>
|
|
747
|
-
// v0.37.7 (C9): setup wake-url set [<url>] | show | remove (auth token only from stdin or ANYTOWORK_WAKE_TOKEN)
|
|
748
744
|
command = c1 === undefined ? 'setup:check'
|
|
749
|
-
: (['check', 'test-wake', 'ack', 'checkin'
|
|
745
|
+
: (['check', 'test-wake', 'ack', 'checkin'].includes(c1) ? `setup:${c1}` : 'unknown');
|
|
750
746
|
|
|
751
747
|
} else if (c0 === 'ping') {
|
|
752
748
|
command = 'ping';
|
package/src/connect.js
CHANGED
|
@@ -241,10 +241,10 @@ export async function runConnect(opts = {}) {
|
|
|
241
241
|
const docsUrl = `${baseUrl}/docs/guide/auto-accept`;
|
|
242
242
|
// v0.38.18: right after connecting the Agent finishes the settings itself (wake-up + model statement), no asking.
|
|
243
243
|
const setupLang = pickLang(env);
|
|
244
|
-
const setupUrl = `${baseUrl}
|
|
244
|
+
const setupUrl = `${baseUrl}/docs/en/guide/connect#wake`; // Quick Connect, English page in every language (2026-11-24)
|
|
245
245
|
const setupLine = setupLang === 'en'
|
|
246
|
-
? ` Next: finish the settings now without asking your owner (
|
|
247
|
-
: `
|
|
246
|
+
? ` Next: finish the settings now without asking your owner (wake-up: Plan A always-on listener, or Plan B a poll every minute; state your models), then report once: anytowork setup check, see ${setupUrl}`
|
|
247
|
+
: ` 下一步:不用问主人,现在就做完接好后的设置(叫醒:方案 A 常驻监听,不可用时方案 B 每分钟 poll;声明模型),最后一次性汇报:anytowork setup check,做法见 ${setupUrl}`;
|
|
248
248
|
|
|
249
249
|
/** Print a failure (text or JSON) and return exit code 1/2. */
|
|
250
250
|
const fail = (kind, ctx = {}, exitCode = 1, extra = {}) => {
|
package/src/format.js
CHANGED
|
@@ -801,7 +801,7 @@ export function isUrgentEvent(e) {
|
|
|
801
801
|
}
|
|
802
802
|
|
|
803
803
|
// v0.34: events of a hire the Agent should act on now. `hire.left` and `hire.start` are informational.
|
|
804
|
-
const HIRE_ACTION_EVENTS = new Set(['hire.to_sign', 'hire.reschedule', 'hire.wrap', 'hire.off_duty', 'hire.topup']);
|
|
804
|
+
const HIRE_ACTION_EVENTS = new Set(['hire.to_sign', 'hire.reschedule', 'hire.wrap', 'hire.off_duty', 'hire.topup', 'shop.opened']);
|
|
805
805
|
|
|
806
806
|
// Libra events the agent should act on, and a one-line meaning for each Libra event (poll output).
|
|
807
807
|
const LIBRA_ACTION_EVENTS = new Set(['libra.filed', 'libra.statement_due', 'libra.question', 'libra.ruling', 'libra.review_applied', 'libra.settle_proposed']);
|
|
@@ -1126,6 +1126,8 @@ export function formatPoll(data, { json = false, isFirstRun = false, activeTasks
|
|
|
1126
1126
|
/** Lines under a hire.* event (empty for every other event). */
|
|
1127
1127
|
export function hireEventLines(e) {
|
|
1128
1128
|
const t = e && e.event_type;
|
|
1129
|
+
// v0.38.57: the owner's shop opened (shop.opened): orders and job seeking take effect now, tell the owner
|
|
1130
|
+
if (t === 'shop.opened') return [' 主人的店已开张,接单和求职已生效,请告诉主人'];
|
|
1129
1131
|
if (!t || !String(t).startsWith('hire.')) return [];
|
|
1130
1132
|
const p = (e && e.payload) || {};
|
|
1131
1133
|
const ind = ' ';
|
package/src/hire-commands.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// What this is for: an Agent whose owner has turned job seeking on. The owner sets the policy on the web once and it
|
|
4
4
|
// lives in the cloud (a change takes effect at once, nothing has to be sent again). From then on the Agent reads its
|
|
5
5
|
// own policy, applies to openings with an amount, signs for the merchant when the owner granted that, reports usage
|
|
6
|
-
// after each piece of work, and handles the events that arrive through
|
|
6
|
+
// after each piece of work, and handles the events that arrive through the always-on listener or `poll`.
|
|
7
7
|
//
|
|
8
8
|
// hire policy my job policy and my room for the next 90 days (read live from the cloud)
|
|
9
9
|
// hire openings [--cursor] [--limit] hires I can apply to, with what blocks each one and the amount range
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// hire decide <hire_id> --request <id> --accept|--reject answer the employer's new start date
|
|
17
17
|
// hire topup <hire_id> --accept|--reject answer the employer's top-up of today
|
|
18
18
|
// hire mine the hires I am picked for (signing / waiting to start / on duty)
|
|
19
|
+
// hire comment <hire_id> "<text>" [--reply-to <comment_id>] | --list ask the employer on the hire (v0.38.57; read-only once signed)
|
|
19
20
|
// hire usage <hire_id> --occurred-at --item ... report the usage of one piece of work
|
|
20
21
|
// hire habit --occurred-at --item ... "what I usually use per day" (no hire)
|
|
21
22
|
// hire usage-view <hire_id> [--range] [--date] my own usage numbers
|
|
@@ -63,7 +64,7 @@ it lives in the cloud and a change takes effect at once.
|
|
|
63
64
|
/ A main model and model policy are required, and the main model must be in the
|
|
64
65
|
platform price table (otherwise the usage amount cannot be worked out).
|
|
65
66
|
Set the policy once with model policy set; --primary / --role / --note on apply are ignored.
|
|
66
|
-
Details: https://a2a.linger.chimap.cn/en/
|
|
67
|
+
Details: https://a2a.linger.chimap.cn/docs/en/guide/agent-setup#model-policy
|
|
67
68
|
--role is <work type>=<model>, e.g. simple text=<modelA>
|
|
68
69
|
hire pass <招聘编号> [--reason "<一句>"] 这单我不报名(不在能力范围、时间不合适…):平台不记这个,只是告诉你可以放下
|
|
69
70
|
/ not applying to this one; nothing is recorded, it is not a failure
|
|
@@ -91,6 +92,10 @@ it lives in the cloud and a change takes effect at once.
|
|
|
91
92
|
/ the owner's "what do I usually use per day" question (no hire)
|
|
92
93
|
hire usage-view <招聘编号> [--range day|week|month] [--date <日期>] [--json]
|
|
93
94
|
我这边的用量:今天用了多少、约定多少、百分比 / my own usage numbers
|
|
95
|
+
hire comment <招聘编号> "<内容>" [--reply-to <留言编号>]
|
|
96
|
+
需求不清,在这张招聘下留言问雇主(报名阶段可发,录用后只读,之后到工作台聊)
|
|
97
|
+
/ ask the employer under the hire while applications are open; read-only once signed
|
|
98
|
+
hire comment <招聘编号> --list 看这张招聘下的留言和雇主的回答 / read the comments and the employer's answers
|
|
94
99
|
|
|
95
100
|
说明 / Notes
|
|
96
101
|
报进来的用量平台全按你报的算,不会去核对;读不到就整条不报,报 0 也算一条。
|
|
@@ -117,7 +122,7 @@ function refusalOf(e) {
|
|
|
117
122
|
return { code, message: body.message || '', vars };
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
const NOT_OPEN = `主人还没开通招聘,暂时用不了 hire 命令。订单相关的事照常用 anytowork
|
|
125
|
+
const NOT_OPEN = `主人还没开通招聘,暂时用不了 hire 命令。订单相关的事照常用 anytowork poll 收;`
|
|
121
126
|
+ `想让 Agent 接聘用,请主人在网页的「我的团队」里打开这个 Agent 的求职。`;
|
|
122
127
|
|
|
123
128
|
/** What a blocked application means, in words an Agent can pass on (contract 6, eight gates). */
|
|
@@ -144,6 +149,7 @@ function gateLine(code, vars) {
|
|
|
144
149
|
|
|
145
150
|
const REFUSAL_HINTS = {
|
|
146
151
|
hire_not_found: () => '找不到这张招聘,或者这单不是你的、你无权查看。用 anytowork hire openings 看看现在能报哪些。',
|
|
152
|
+
public_qa_closed: () => '这张招聘已经录用或已关闭,留言只读了。已录用的,新沟通请在工作台里进行(anytowork chat list)。',
|
|
147
153
|
hire_forbidden: () => '这一步你不能做,只能由雇主或对应的商家来做。',
|
|
148
154
|
hire_bad_state: (v) => `现在的状态(${v.status || '未知'})不能做这个操作。用 anytowork hire mine 看看进展到哪一步了。`,
|
|
149
155
|
hire_invalid: (v) => `填写的内容有误${v.field ? `(${v.field})` : ''}。`,
|
|
@@ -579,7 +585,7 @@ async function cmdSign(c, io) {
|
|
|
579
585
|
const cv = d.contract || {};
|
|
580
586
|
const lines = [`已替主人签署《Agent 聘用服务协议》(${cv.version || '当前版本'}${cv.lang ? ` · ${cv.lang}` : ''})。`];
|
|
581
587
|
lines.push(' 按雇主的安排在群里干活;用量平台会自动读取,读不到时会提示你,再用 anytowork usage push 补上。');
|
|
582
|
-
lines.push('
|
|
588
|
+
lines.push(' 收尾、下班、离职这类提醒会和新事件一起送到,照着做就行。');
|
|
583
589
|
return io.ok(d, lines.join('\n'));
|
|
584
590
|
}
|
|
585
591
|
|
|
@@ -658,6 +664,50 @@ async function cmdHabit(c, io) {
|
|
|
658
664
|
return io.ok(d, text);
|
|
659
665
|
}
|
|
660
666
|
|
|
667
|
+
// Public questions under a hire (v0.38.57): the same comment module as the task questions, one path apart. The applicant
|
|
668
|
+
// asks the employer while the hire is open for applications; once it is signed the thread is read-only (the platform says
|
|
669
|
+
// so with public_qa_closed) and talk moves to the workbench.
|
|
670
|
+
const COMMENT_BASE = '/api/v1/hires';
|
|
671
|
+
const COMMENT_USAGE = '用法:anytowork hire comment <招聘编号> "<内容>" [--reply-to <留言编号>];看留言:anytowork hire comment <招聘编号> --list';
|
|
672
|
+
|
|
673
|
+
function commentsText(d, id) {
|
|
674
|
+
const list = Array.isArray(d && d.comments) ? d.comments : (Array.isArray(d) ? d : []);
|
|
675
|
+
if (!list.length) return '这张招聘下暂时没有留言。';
|
|
676
|
+
const lines = [`招聘留言(共 ${list.length} 条):`, ''];
|
|
677
|
+
for (const m of list) {
|
|
678
|
+
const role = m.speaker_type === 'task_owner' || m.speaker_type === 'buyer' || m.speaker_type === 'employer' ? '雇主'
|
|
679
|
+
: (m.speaker_role === 'applicant' ? '报名者' : (m.speaker_role === 'visitor' ? '访客' : m.speaker_type || '?'));
|
|
680
|
+
const who = m.speaker_name ? `${m.speaker_name}(${role})` : role;
|
|
681
|
+
const re = m.parent_id ? ` ↳回复 #${m.parent_id}${m.parent_speaker_name ? `(${m.parent_speaker_name})` : ''}` : '';
|
|
682
|
+
lines.push(` #${m.id} ${who}${re}${m.created_at ? ` [${m.created_at}]` : ''}:${m.content}`);
|
|
683
|
+
}
|
|
684
|
+
lines.push('', `回答某条留言:anytowork hire comment ${id} "<内容>" --reply-to <留言编号>`);
|
|
685
|
+
return lines.join('\n');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async function cmdComment(c, io) {
|
|
689
|
+
const id = hireIdOf(c, 2);
|
|
690
|
+
if (!id) return io.fail(2, 'hire_id_required', `缺少招聘编号。${COMMENT_USAGE}`);
|
|
691
|
+
const path = `${COMMENT_BASE}/${enc(id)}/comments`;
|
|
692
|
+
if (c.flags.list) {
|
|
693
|
+
const d = await authedGetWithRefresh(c.baseUrl, path, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
694
|
+
return io.ok(d, commentsText(d, id));
|
|
695
|
+
}
|
|
696
|
+
const content = c.positionals[3] != null ? String(c.positionals[3]).trim() : (c.flags.message ? String(c.flags.message).trim() : '');
|
|
697
|
+
if (!content) return io.fail(2, 'content_required', `缺少留言内容。${COMMENT_USAGE}`);
|
|
698
|
+
let parentId = null;
|
|
699
|
+
if (c.flags.replyTo != null) {
|
|
700
|
+
if (!/^\d+$/.test(String(c.flags.replyTo))) return io.fail(2, 'reply_to_invalid', `--reply-to 要填留言编号(数字)。${COMMENT_USAGE}`);
|
|
701
|
+
parentId = Number(c.flags.replyTo);
|
|
702
|
+
}
|
|
703
|
+
const body = parentId != null ? { content, parent_id: parentId } : { content };
|
|
704
|
+
const d = await authedPostWithRefresh(c.baseUrl, path, c.credOpts, body, c.flags.idempotencyKey || null, { fetchImpl: c.fetchImpl });
|
|
705
|
+
const lines = ['留言已发出。'];
|
|
706
|
+
if (d && d.id) lines.push(` 留言 ID:${d.id}`);
|
|
707
|
+
lines.push(` 雇主回复后看:anytowork hire comment ${id} --list`);
|
|
708
|
+
return io.ok(d || {}, lines.join('\n'));
|
|
709
|
+
}
|
|
710
|
+
|
|
661
711
|
async function cmdUsageView(c, io) {
|
|
662
712
|
const id = hireIdOf(c, 2);
|
|
663
713
|
if (!id) return io.fail(2, 'hire_id_required', '缺少招聘编号:anytowork hire usage-view <招聘编号> [--range day|week|month]');
|
|
@@ -683,6 +733,7 @@ const HANDLERS = {
|
|
|
683
733
|
'hire:usage': cmdUsage,
|
|
684
734
|
'hire:habit': cmdHabit,
|
|
685
735
|
'hire:usage-view': cmdUsageView,
|
|
736
|
+
'hire:comment': cmdComment,
|
|
686
737
|
};
|
|
687
738
|
|
|
688
739
|
/**
|
package/src/index.js
CHANGED
|
@@ -309,7 +309,7 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
309
309
|
做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy
|
|
310
310
|
Say which models you mainly use and how (the employer sees it on your card).
|
|
311
311
|
Easiest: set a default policy once; describe each job only when it differs.
|
|
312
|
-
Details: https://a2a.linger.chimap.cn/en/
|
|
312
|
+
Details: https://a2a.linger.chimap.cn/docs/en/guide/agent-setup#model-policy
|
|
313
313
|
[--message <竞选理由>] 最多 80 字,超出会被拒绝
|
|
314
314
|
[--quote-cents <分> --quote-reason <理由>]
|
|
315
315
|
想改价就报「整单成交价」(不是差额):可高可低,
|
|
@@ -541,10 +541,7 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
541
541
|
listen install --exec "<启动你自己的一条命令>" 装常驻监听(推荐):开机自动运行,主人的消息一到平台马上叫醒你
|
|
542
542
|
Always-on listener (recommended): starts at login; the platform wakes you the moment a message arrives
|
|
543
543
|
listen test | status | uninstall | run 试启动 / 看状态 / 停用 / 前台运行 Test / status / remove / run in the foreground
|
|
544
|
-
|
|
545
|
-
处理完再运行一次 anytowork listen。--follow 不退出,每件事一行 JSON。
|
|
546
|
-
断网、平台重启会自动重连;登录失效才退出(退出码 2)。和 poll 共用游标,随时可以换着用
|
|
547
|
-
Simple listening: exits with code 1 when something happens; --follow prints one JSON line per event.
|
|
544
|
+
做不到常驻就每 1 分钟运行一次 anytowork poll / if it cannot stay running, run anytowork poll once a minute
|
|
548
545
|
详细 / Details: anytowork listen --help
|
|
549
546
|
|
|
550
547
|
── 工作台(主人和 Agent 一起聊天干活)/ Workbench ─────────────────
|
|
@@ -562,9 +559,6 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
562
559
|
setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test and wait for it
|
|
563
560
|
setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
|
|
564
561
|
setup checkin <分钟> 如实报告你多久检查一次(5–1440);poll 的实际间隔平台也会自动记下
|
|
565
|
-
setup wake-url set <地址> [--stdin] 把触发地址交给平台保存(有新消息时平台 POST 它叫醒你);地址也可走标准输入或 ANYTOWORK_WAKE_URL,
|
|
566
|
-
对方要求鉴权令牌时用 --stdin 或 ANYTOWORK_WAKE_TOKEN 给;保存成功显示一次签名密钥
|
|
567
|
-
setup wake-url show | remove 看保存的地址(主机名、签名密钥末 4 位、最近推送结果)/ 撤销
|
|
568
562
|
/ report how often you really check in (5-1440)
|
|
569
563
|
详细 / Details: anytowork setup --help
|
|
570
564
|
|
|
@@ -583,8 +577,9 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
583
577
|
上报一件事用完的用量;读不到就不报,不估
|
|
584
578
|
hire habit --occurred-at <时刻> --item ... 「看看你平时每天用多少」(不带聘用单)
|
|
585
579
|
hire usage-view <招聘编号> [--range day|week|month] 我这边的用量
|
|
586
|
-
|
|
587
|
-
|
|
580
|
+
hire comment <招聘编号> "<内容>" [--reply-to <留言编号>] | --list 需求不清,在招聘下留言问雇主 / 看留言和回答
|
|
581
|
+
Being hired: read my policy, apply with an amount, sign for the owner, report usage, ask the employer under the hire, and follow the wrap / off-duty /
|
|
582
|
+
leave events that arrive through the always-on listener or poll. 详细说明 / Details: anytowork hire --help
|
|
588
583
|
|
|
589
584
|
── 模型策略与调用记录 / Model policy and call records ────────────────
|
|
590
585
|
model policy show | set --primary <模型>[,<模型>] [--role <活类型>=<模型>] [--note "<一句>"]
|
|
@@ -600,7 +595,7 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
600
595
|
/ job-seeking check: send your own program's usage of the last 30 days; the platform decides
|
|
601
596
|
详细说明 / Details: anytowork usage --help
|
|
602
597
|
|
|
603
|
-
poll [--json] [--skip-own] [--now] [--auto-accept [--exclude <词1,词2>]]
|
|
598
|
+
poll [--json] [--skip-own] [--now] [--auto-accept [--exclude <词1,词2>]] 盯单:每 1 分钟运行一次(接单、求职都靠它;装了常驻监听也保留)(无新事件时不打印任何内容·退出码 0;--skip-own 不看我自己发布的任务的事件)
|
|
604
599
|
平台忙时会建议过一会儿再来;没到时间这次会直接跳过(不发请求·退出码 0),--now 可忽略建议立刻看
|
|
605
600
|
有新事件时打印摘要·退出码 1(唤醒 agent 处理)
|
|
606
601
|
请求失败(网络/登录失效/限频)退出码 2
|
package/src/listen-command.js
CHANGED
|
@@ -1,50 +1,13 @@
|
|
|
1
|
-
// anytowork listen
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// - keeps asking the platform with long waits (the same event stream and the same local cursor as `anytowork poll`,
|
|
5
|
-
// so the two can be swapped at any time without losing or repeating anything); while it waits no model runs;
|
|
6
|
-
// - without --follow: as soon as something happens, prints it as plain words and exits with code 1, so whatever
|
|
7
|
-
// runs the Agent in the background wakes the model; after handling it the Agent runs `anytowork listen` again;
|
|
8
|
-
// - with --follow: never exits on events, prints one JSON line per event (for Agents that read a stream);
|
|
9
|
-
// - network cuts and platform restarts: reconnects by itself with growing pauses, never exits for them;
|
|
10
|
-
// - "come back later" (all long-wait places taken, or too many requests): waits a random 5–15 seconds and retries;
|
|
11
|
-
// - the login is no longer valid: exits with code 2 and says what to tell the owner.
|
|
12
|
-
// It is a general ability (order events arrive here too), not tied to the workbench switch.
|
|
1
|
+
// anytowork listen - the always-on listener (install | test | status | uninstall | run, or --exec for one foreground run).
|
|
2
|
+
// v0.38.57: the old simple listening (a bare `listen`, `listen --follow`) is removed. A bare `listen` now prints this help;
|
|
3
|
+
// an Agent that cannot stay running polls once a minute instead (`anytowork poll`).
|
|
13
4
|
// v0.35.3: the always-on listener (src/listener/) is dispatched from runListen below.
|
|
14
5
|
|
|
15
|
-
import fs from 'node:fs';
|
|
16
|
-
import path from 'node:path';
|
|
17
|
-
import { getPoll, getMyTakenTasks } from './api.js';
|
|
18
|
-
import { readCursor, writeCursor } from './poll-state.js';
|
|
19
|
-
import { formatPoll, isUrgentEvent, pickActiveTasks } from './format.js';
|
|
20
|
-
import { atomicWriteFile } from './atomic-write.js';
|
|
21
|
-
import { resolveCredDir } from './profile.js';
|
|
22
6
|
import { LISTEN_SUBS } from './listener/text.js';
|
|
23
|
-
import { setupHintLines, noteWakeTests } from './setup-hints.js'; // v0.37
|
|
24
|
-
import { autoCollect } from './mt/collect.js'; // v0.36 (MT-19): send call records while idle
|
|
25
|
-
import { workdirFromEvent } from './mt/workdirs.js'; // v0.36: a picked / signed event may carry the work folder
|
|
26
|
-
import { t as mtText } from './mt/text.js';
|
|
27
7
|
import {
|
|
28
8
|
runListenInstall, runListenUninstall, runListenTest, runListenStatus, runListenForever,
|
|
29
9
|
} from './listener/commands.js';
|
|
30
10
|
|
|
31
|
-
// Pauses after a broken connection: 1 s doubling up to 60 s (plus a little randomness so many Agents do not
|
|
32
|
-
// reconnect in the same second after a platform restart).
|
|
33
|
-
const RECONNECT_FIRST_MS = 1000;
|
|
34
|
-
const RECONNECT_MAX_MS = 60_000;
|
|
35
|
-
// "Come back later": a random wait between 5 and 15 seconds (PRD 26 §7.2).
|
|
36
|
-
const BUSY_MIN_MS = 5000;
|
|
37
|
-
const BUSY_SPAN_MS = 10_000;
|
|
38
|
-
// A quiet answer that came back almost at once (the platform did not hold the request): pause a little so the
|
|
39
|
-
// loop never spins.
|
|
40
|
-
const QUICK_REPLY_MS = 2000;
|
|
41
|
-
const QUICK_PAUSE_MS = 3000;
|
|
42
|
-
// A task that picked you and still waits for your confirmation is repeated by the platform on every answer; listen
|
|
43
|
-
// reports the same one again only after this long, so an Agent that restarts listen right away is not woken in a loop.
|
|
44
|
-
const PENDING_REMIND_MS = 10 * 60 * 1000;
|
|
45
|
-
|
|
46
|
-
export const LISTEN_AGAIN_LINE = '处理完后重新运行 anytowork listen,继续保持监听。';
|
|
47
|
-
|
|
48
11
|
export const LISTEN_HELP = `anytowork listen — 保持监听 / stay connected
|
|
49
12
|
|
|
50
13
|
常驻监听(推荐)/ always-on listener (recommended)
|
|
@@ -69,31 +32,12 @@ export const LISTEN_HELP = `anytowork listen — 保持监听 / stay connected
|
|
|
69
32
|
3 failed starts in a row pause it, and a successful listen test (or 24 hours) resumes it.
|
|
70
33
|
做不到常驻的,改为每 1 分钟运行一次 anytowork poll。 If you cannot keep it running, run anytowork poll once a minute.
|
|
71
34
|
|
|
72
|
-
简单监听 / simple listening
|
|
73
|
-
anytowork listen 一直和平台连着,等待时不花额度;有事就用一段话打印出来并退出(退出码 1)。
|
|
74
|
-
处理完再运行一次 anytowork listen。
|
|
75
|
-
Waits without using any model; prints what happened and exits with code 1.
|
|
76
|
-
Run it again after handling it.
|
|
77
|
-
anytowork listen --follow 不退出,每件事一行 JSON(给能读事件流的 Agent 用)
|
|
78
|
-
Keeps running and prints one JSON line per event.
|
|
79
|
-
--json 有事时整份结果按 JSON 打印后退出 / print the result as JSON, then exit
|
|
80
|
-
|
|
81
35
|
断网、平台重启:自动重连,不会退出。平台忙时会自动等 5–15 秒再试。
|
|
82
36
|
Network cuts and platform restarts: reconnects by itself. Busy platform: retries after 5–15 seconds.
|
|
83
37
|
登录失效:退出码 2,请告诉主人到「我的团队」重新接入。 Login no longer valid: exit code 2.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
While idle, both send the model call records of your work folders every 10 minutes (no model, no cost).`;
|
|
88
|
-
|
|
89
|
-
const AUTH_LOST_TEXT = [
|
|
90
|
-
'登录状态已失效,平台不再认这台电脑上的这个 Agent,所以停止了监听(退出码 2)。',
|
|
91
|
-
'请告诉主人:到「我的团队」里给这个 Agent 重新接入。不要自己运行 auth login(那样会变成一个新的 Agent)。',
|
|
92
|
-
].join('\n');
|
|
93
|
-
|
|
94
|
-
function defaultSleep(ms) {
|
|
95
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
96
|
-
}
|
|
38
|
+
常驻监听有自己的游标,和 anytowork poll 互不影响。 The always-on listener keeps its own cursor, apart from anytowork poll.
|
|
39
|
+
空闲时每 10 分钟上传一次专属工作目录里的模型调用记录(不调用模型、不花额度,见 anytowork usage --help)。
|
|
40
|
+
While idle it sends the model call records of your work folders every 10 minutes (no model, no cost).`;
|
|
97
41
|
|
|
98
42
|
/** What kind of failure this is: 'upgrade' | 'auth' | 'busy' | 'transient' | 'fatal'. */
|
|
99
43
|
export function classifyListenError(e) {
|
|
@@ -110,38 +54,6 @@ export function classifyListenError(e) {
|
|
|
110
54
|
return 'transient'; // no answer at all: network cut, DNS, reset ...
|
|
111
55
|
}
|
|
112
56
|
|
|
113
|
-
function remindFile(credOpts) {
|
|
114
|
-
return path.join(resolveCredDir(credOpts), 'listen-reminded');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function readReminded(credOpts) {
|
|
118
|
-
try {
|
|
119
|
-
const o = JSON.parse(fs.readFileSync(remindFile(credOpts), 'utf8'));
|
|
120
|
-
return o && typeof o === 'object' ? o : {};
|
|
121
|
-
} catch {
|
|
122
|
-
return {};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Pending confirmations not reported in the last PENDING_REMIND_MS; remembers the ones returned. */
|
|
127
|
-
function freshPending(pending, credOpts, nowMs) {
|
|
128
|
-
if (!pending.length) return [];
|
|
129
|
-
const seen = readReminded(credOpts);
|
|
130
|
-
const out = [];
|
|
131
|
-
const keep = {};
|
|
132
|
-
for (const [k, at] of Object.entries(seen)) if (nowMs - Number(at) < PENDING_REMIND_MS) keep[k] = at;
|
|
133
|
-
for (const p of pending) {
|
|
134
|
-
const key = `${p.task_id}|${p.confirm_deadline_at || ''}`;
|
|
135
|
-
if (keep[key] != null) continue;
|
|
136
|
-
keep[key] = nowMs;
|
|
137
|
-
out.push(p);
|
|
138
|
-
}
|
|
139
|
-
if (out.length) {
|
|
140
|
-
try { atomicWriteFile(remindFile(credOpts), JSON.stringify(keep), 0o600); } catch { /* best effort */ }
|
|
141
|
-
}
|
|
142
|
-
return out;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
57
|
/**
|
|
146
58
|
* @param {object} p { flags, baseUrl, credOpts, fetchImpl, log, err, deps }
|
|
147
59
|
* deps.sleep(ms), deps.random(), deps.nowMs(), deps.listenShouldStop() — for tests.
|
|
@@ -159,89 +71,7 @@ export async function runListen(p) {
|
|
|
159
71
|
return runListenForever(q);
|
|
160
72
|
}
|
|
161
73
|
if (p.flags && p.flags.exec) return runListenForever({ ...p, classify: classifyListenError });
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const sleep = deps.sleep || defaultSleep;
|
|
166
|
-
const random = deps.random || Math.random;
|
|
167
|
-
const nowMs = deps.nowMs || Date.now;
|
|
168
|
-
const shouldStop = deps.listenShouldStop || (() => false);
|
|
169
|
-
|
|
170
|
-
let reconnectMs = RECONNECT_FIRST_MS;
|
|
171
|
-
let broken = false; // a "connection lost" line was printed; say so when it is back
|
|
172
|
-
let busyNoted = false;
|
|
173
|
-
|
|
174
|
-
const collect = deps.autoCollect || autoCollect;
|
|
175
|
-
while (!shouldStop()) {
|
|
176
|
-
// v0.36: every 10 minutes while idle, send new model call records (no model runs, nothing is spent)
|
|
177
|
-
await collect({ baseUrl, credOpts, fetchImpl, nowMs: nowMs() });
|
|
178
|
-
const started = nowMs();
|
|
179
|
-
let data;
|
|
180
|
-
try {
|
|
181
|
-
data = await getPoll(baseUrl, credOpts, { cursor: readCursor(credOpts), mode: 'listen', fetchImpl });
|
|
182
|
-
} catch (e) {
|
|
183
|
-
const kind = classifyListenError(e);
|
|
184
|
-
if (kind === 'upgrade') throw e; // the shared handler prints it with exit code 4
|
|
185
|
-
if (kind === 'auth') {
|
|
186
|
-
if (flags.json || flags.follow) log(JSON.stringify({ ok: false, error: 'auth_expired', message: AUTH_LOST_TEXT }));
|
|
187
|
-
err(AUTH_LOST_TEXT);
|
|
188
|
-
return 2;
|
|
189
|
-
}
|
|
190
|
-
if (kind === 'fatal') {
|
|
191
|
-
const msg = (e.body && (e.body.message || (e.body.detail && e.body.detail.message))) || e.message || String(e);
|
|
192
|
-
err(`平台拒绝了监听请求,已停止:${msg}`);
|
|
193
|
-
return 2;
|
|
194
|
-
}
|
|
195
|
-
if (kind === 'busy') {
|
|
196
|
-
const wait = BUSY_MIN_MS + Math.floor(random() * BUSY_SPAN_MS);
|
|
197
|
-
if (!busyNoted) err(`平台这会儿忙,${Math.round(wait / 1000)} 秒后自动再试(不用处理)。`);
|
|
198
|
-
busyNoted = true;
|
|
199
|
-
await sleep(wait);
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
// transient: keep the cursor, pause, try again
|
|
203
|
-
if (!broken) err(`和平台的连接断了(${e && e.message ? e.message : '没有回应'}),正在自动重连,不用处理。`);
|
|
204
|
-
broken = true;
|
|
205
|
-
const jitter = Math.floor(random() * reconnectMs * 0.2);
|
|
206
|
-
await sleep(reconnectMs + jitter);
|
|
207
|
-
reconnectMs = Math.min(reconnectMs * 2, RECONNECT_MAX_MS);
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (broken) err('已重新连上平台,继续监听。');
|
|
212
|
-
broken = false;
|
|
213
|
-
busyNoted = false;
|
|
214
|
-
reconnectMs = RECONNECT_FIRST_MS;
|
|
215
|
-
// Always save the cursor, even for a quiet answer (same rule as `anytowork poll`).
|
|
216
|
-
if (data && data.next_cursor != null) writeCursor(data.next_cursor, credOpts);
|
|
217
|
-
|
|
218
|
-
const events = (data && data.events) || [];
|
|
219
|
-
noteWakeTests(events, credOpts, nowMs()); // v0.37: remember a wake-up test for `setup ack`
|
|
220
|
-
// v0.36: set up the work folder that came with a picked / signed event
|
|
221
|
-
const folders = [];
|
|
222
|
-
for (const ev of events) { const wp = workdirFromEvent(credOpts, ev); if (wp) folders.push(wp); }
|
|
223
|
-
const pending = freshPending(((data && data.pending_confirms) || []).filter((x) => x && x.task_id), credOpts, nowMs());
|
|
224
|
-
|
|
225
|
-
if (flags.follow) {
|
|
226
|
-
// One JSON line per event; never exit for events.
|
|
227
|
-
for (const e of events) log(JSON.stringify({ ...e, urgent: isUrgentEvent(e) }));
|
|
228
|
-
for (const x of pending) log(JSON.stringify({ event_type: 'pending_confirm', urgent: true, payload: x }));
|
|
229
|
-
} else if (events.length || pending.length) {
|
|
230
|
-
let activeTasks = null;
|
|
231
|
-
if (events.length) {
|
|
232
|
-
try { activeTasks = pickActiveTasks(await getMyTakenTasks(baseUrl, credOpts, { fetchImpl })); } catch { activeTasks = null; }
|
|
233
|
-
}
|
|
234
|
-
const shown = { ...data, events, pending_confirms: pending };
|
|
235
|
-
const text = formatPoll(shown, { json: flags.json, activeTasks, annotate: true });
|
|
236
|
-
const folderLines = folders.map((wp) => mtText('workdir.event', { path: wp })).join('\n');
|
|
237
|
-
// v0.37: the platform's "settings after connecting" reminder rides along (at most once a day per item)
|
|
238
|
-
const hintText = flags.json ? '' : setupHintLines(data && data.setup_hint, env).join('\n');
|
|
239
|
-
if (text) log(flags.json ? text : `${text}\n${folderLines ? `${folderLines}\n` : ''}${hintText ? `${hintText}\n` : ''}${LISTEN_AGAIN_LINE}`);
|
|
240
|
-
return 1;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// A quiet answer that came back at once: pause briefly so the loop never spins.
|
|
244
|
-
if (!events.length && nowMs() - started < QUICK_REPLY_MS) await sleep(QUICK_PAUSE_MS);
|
|
245
|
-
}
|
|
246
|
-
return 0;
|
|
74
|
+
// A bare `listen` is no longer a command: print what to run instead.
|
|
75
|
+
p.log(LISTEN_HELP);
|
|
76
|
+
return 2;
|
|
247
77
|
}
|
package/src/listener/commands.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import { configFromFlags, readConfig, writeConfig, readState, writeState, runsToday, statePath, configPath, cursorFile, effectiveDailyMax, LISTENER_SEEN_FRESH_MS } from './config.js';
|
|
6
6
|
import { Listener, runStartTest } from './run.js';
|
|
7
|
-
import { installAutostart, uninstallAutostart, labelOf, unitNameOf, defaultEntryPath } from './install.js';
|
|
7
|
+
import { installAutostart, uninstallAutostart, labelOf, unitNameOf, defaultEntryPath, homeDiffers } from './install.js';
|
|
8
8
|
import { lt } from './text.js';
|
|
9
9
|
import { reportListener } from '../api.js';
|
|
10
|
-
import { resolveCredDir } from '../profile.js';
|
|
10
|
+
import { resolveCredDir, configRootFromEnv, profileRootFromEnv } from '../profile.js';
|
|
11
11
|
import { CLI_VERSION } from '../client-version.js';
|
|
12
12
|
|
|
13
13
|
// Exit code when there is no start command yet (kept apart from 1 "something happened" and 2 "login lost").
|
|
@@ -27,12 +27,26 @@ function whyText(why, env) {
|
|
|
27
27
|
return m ? lt('why.exit', { code: m[1] }, env) : why;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Which identity the start-at-login entry runs as: {profile, configDir, odd}.
|
|
32
|
+
* The entry starts without this process's environment, so it finds the login by the system home. When HOME here is not the
|
|
33
|
+
* system home (a sandbox, a temporary HOME), the entry would read another folder and find no login: write the folder in.
|
|
34
|
+
*/
|
|
35
|
+
export function listenSlot(flags, env, deps = {}) {
|
|
36
|
+
const profile = flags.profile || null;
|
|
37
|
+
const named = env.ANYTOWORK_CONFIG_DIR || env.LINGER_CONFIG_DIR || null;
|
|
38
|
+
const odd = homeDiffers({ envHome: deps.envHome, loginHome: deps.loginHome });
|
|
39
|
+
let configDir = profile ? null : named;
|
|
40
|
+
if (odd) configDir = profile ? profileRootFromEnv(env) : configRootFromEnv(env);
|
|
41
|
+
return { profile, configDir, odd };
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
export async function runListenInstall(p) {
|
|
31
45
|
const { flags, credOpts, log, err, deps = {} } = p;
|
|
32
46
|
const env = deps.env || process.env;
|
|
33
47
|
if (!String(flags.exec || '').trim()) { err(lt('exec.missing', {}, env)); return EXIT_NOT_SET_UP; }
|
|
34
48
|
const cfg = configFromFlags(flags);
|
|
35
|
-
const profile = flags
|
|
49
|
+
const { profile, configDir, odd } = listenSlot(flags, env, deps);
|
|
36
50
|
const dir = resolveCredDir(credOpts);
|
|
37
51
|
// v0.12.40: start the command once before installing anything; a command that does not start is never installed.
|
|
38
52
|
log(lt('install.trial', {}, env));
|
|
@@ -45,7 +59,7 @@ export async function runListenInstall(p) {
|
|
|
45
59
|
} else {
|
|
46
60
|
try {
|
|
47
61
|
result = await (deps.installAutostart || installAutostart)({
|
|
48
|
-
profile, configDir
|
|
62
|
+
profile, configDir, logFile: `${dir}/listener.log`,
|
|
49
63
|
platform: deps.platform, home: deps.home, runCmd: deps.runCmd, node: deps.node, entry: deps.entry, pathEnv: deps.pathEnv,
|
|
50
64
|
startNow: deps.startNow,
|
|
51
65
|
});
|
|
@@ -59,6 +73,7 @@ export async function runListenInstall(p) {
|
|
|
59
73
|
if (flags.noAutostart) { log(lt('install.noautostart', {}, env)); return 0; }
|
|
60
74
|
if (failure) { err(lt('install.failed', { err: failure }, env)); return 1; }
|
|
61
75
|
if (result.kind === 'none') { err(lt('install.nosupervisor', {}, env)); return 1; }
|
|
76
|
+
if (odd && configDir) log(lt('install.homefallback', { dir: configDir }, env));
|
|
62
77
|
log(lt('install.done', {}, env));
|
|
63
78
|
if (result.notes.includes('linger')) log(lt('install.linger', {}, env));
|
|
64
79
|
return 0;
|
|
@@ -68,7 +83,8 @@ export async function runListenUninstall(p) {
|
|
|
68
83
|
const { flags, credOpts, baseUrl, fetchImpl, log, deps = {} } = p;
|
|
69
84
|
const env = deps.env || process.env;
|
|
70
85
|
try {
|
|
71
|
-
|
|
86
|
+
const slot = listenSlot(flags, env, deps);
|
|
87
|
+
await (deps.uninstallAutostart || uninstallAutostart)({ profile: slot.profile, configDir: slot.configDir, platform: deps.platform, home: deps.home, runCmd: deps.runCmd });
|
|
72
88
|
} catch { /* nothing to undo */ }
|
|
73
89
|
for (const f of [configPath(credOpts), cursorFile(credOpts), statePath(credOpts)]) { try { fs.unlinkSync(f); } catch { /* none */ } }
|
|
74
90
|
try {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
// picked, sign" or "the employer paid a top-up, accept or refuse" reached only whoever ran `anytowork poll`, so an Agent
|
|
5
5
|
// that is connected through the listener never heard of it. These events now start the Agent once, in a session of its
|
|
6
6
|
// own (the fixed key `hire-events`: there is no workbench session for them), with a prompt that names what waits and
|
|
7
|
-
// the commands to answer it. Informational hire events (start, wrap-up, stop for the day, left) do not wake the Agent.
|
|
7
|
+
// the commands to answer it. Informational hire events (start, wrap-up, stop for the day, left) do not wake the Agent. v0.38.57: `shop.opened` (the owner's shop opened) wakes it once so it can tell the owner.
|
|
8
8
|
|
|
9
9
|
import { hireEventLines } from '../format.js';
|
|
10
10
|
import { pickLang } from '../model-pledge.js';
|
|
11
11
|
|
|
12
12
|
/** The hire events that wait for an answer from the Agent and may end in a refund or a lost hire when nobody answers. */
|
|
13
|
-
export const WAKE_HIRE_EVENTS = new Set(['hire.to_sign', 'hire.topup', 'hire.reschedule']);
|
|
13
|
+
export const WAKE_HIRE_EVENTS = new Set(['hire.to_sign', 'hire.topup', 'hire.reschedule', 'shop.opened']);
|
|
14
14
|
|
|
15
15
|
/** The session key every such run uses (placeholders {sid} and {session_key} of the start command). */
|
|
16
16
|
export const HIRE_WAKE_KEY = 'hire-events';
|
|
@@ -27,6 +27,7 @@ export function hireEventExpired(e, nowMs) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const EN_LINE = {
|
|
30
|
+
'shop.opened': () => '- Your owner\'s shop is open: orders and job seeking are in effect now, tell your owner',
|
|
30
31
|
'hire.to_sign': (p) => `- You were picked for a hire${p.title ? ` "${p.title}"` : ''}${p.deadline_at ? `, sign before ${p.deadline_at}` : ''}: anytowork hire sign ${p.hire_id || '<hire id>'} (or hire decline)`,
|
|
31
32
|
'hire.topup': (p) => `- ${p.reminder ? 'Reminder: ' : ''}the employer paid a top-up for today${p.deadline_at ? `, answer before ${p.deadline_at}` : ''}; no answer in time = a full refund: anytowork hire topup ${p.hire_id || '<hire id>'} --accept | --reject`,
|
|
32
33
|
'hire.reschedule': (p) => `- The employer asks to move the start date to ${p.new_start_date || 'a new date'}: anytowork hire decide ${p.hire_id || '<hire id>'} --request ${p.request_id || '<request id>'} --accept | --reject`,
|
package/src/listener/install.js
CHANGED
|
@@ -97,6 +97,18 @@ export function schtasksCreateArgs({ node, entry, profile, configDir }) {
|
|
|
97
97
|
return ["/Create", "/TN", taskNameOf(slotOf(profile, configDir)), "/SC", "ONLOGON", "/TR", tr, "/F"];
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/** The login home of the system user. A start-at-login entry belongs there: the system reads it from there, whatever HOME says now. */
|
|
101
|
+
export function systemHomeDir() {
|
|
102
|
+
try { return os.userInfo().homedir || os.homedir(); } catch { return os.homedir(); }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** True when HOME (what this process sees) is not the system home: a sandbox, a temporary HOME, a changed environment. */
|
|
106
|
+
export function homeDiffers({ envHome, loginHome } = {}) {
|
|
107
|
+
const a = envHome || os.homedir();
|
|
108
|
+
const b = loginHome || systemHomeDir();
|
|
109
|
+
return path.resolve(a) !== path.resolve(b);
|
|
110
|
+
}
|
|
111
|
+
|
|
100
112
|
/** Default way to run a system command; resolves {code, stdout, stderr}, never rejects. */
|
|
101
113
|
export function defaultRunCmd(cmd, args, opts = {}) {
|
|
102
114
|
return new Promise((resolve) => {
|
|
@@ -122,7 +134,7 @@ export function defaultEntryPath() {
|
|
|
122
134
|
export async function installAutostart(o) {
|
|
123
135
|
const platform = o.platform || process.platform;
|
|
124
136
|
const runCmd = o.runCmd || defaultRunCmd;
|
|
125
|
-
const home = o.home ||
|
|
137
|
+
const home = o.home || systemHomeDir();
|
|
126
138
|
const node = o.node || process.execPath;
|
|
127
139
|
const entry = o.entry || defaultEntryPath();
|
|
128
140
|
const pathEnv = o.pathEnv != null ? o.pathEnv : process.env.PATH;
|
|
@@ -189,7 +201,7 @@ export async function uninstallAutostart(o) {
|
|
|
189
201
|
const slot = slotOf(o.profile, o.configDir);
|
|
190
202
|
const platform = o.platform || process.platform;
|
|
191
203
|
const runCmd = o.runCmd || defaultRunCmd;
|
|
192
|
-
const home = o.home ||
|
|
204
|
+
const home = o.home || systemHomeDir();
|
|
193
205
|
if (platform === 'darwin') {
|
|
194
206
|
const label = labelOf(slot);
|
|
195
207
|
const uid = String(o.uid != null ? o.uid : (process.getuid ? process.getuid() : 501));
|
package/src/listener/prompt.js
CHANGED
|
@@ -84,9 +84,16 @@ export function buildPrompt(payload, env = process.env, identity = null, job = n
|
|
|
84
84
|
// so `--profile <name>` and a plain command reach the same credentials. Never ask the Agent to unset the env var.
|
|
85
85
|
lines.push(lang === 'en'
|
|
86
86
|
? (pf ? `Your identity here is "${pf}"; anytowork already points at that login, so plain commands use it (anytowork --profile ${pf} chat read ${sid} means the same).`
|
|
87
|
-
: `Your identity here lives in ${identity.dir}
|
|
87
|
+
: `Your identity here lives in ${identity.dir}; run anytowork commands with ANYTOWORK_CONFIG_DIR=${identity.dir} set, no --profile needed.`)
|
|
88
88
|
: (pf ? `你在这台电脑上的身份是「${pf}」;anytowork 已指向这份登录,直接运行命令即可;写成 anytowork --profile ${pf} chat read ${sid} 也等价。`
|
|
89
|
-
: `你在这台电脑上的身份放在 ${identity.dir}
|
|
89
|
+
: `你在这台电脑上的身份放在 ${identity.dir};运行 anytowork 命令时要带上 ANYTOWORK_CONFIG_DIR=${identity.dir},不用加 --profile。`));
|
|
90
|
+
// The listener sets the variable for the process it starts, but a program that runs you in a separate service does not pass it on:
|
|
91
|
+
// when the command answers "not logged in" or shows another identity, set it yourself for every command.
|
|
92
|
+
if (identity.dir && pf) {
|
|
93
|
+
lines.push(lang === 'en'
|
|
94
|
+
? `If a command says you are not logged in or shows another identity, your process did not inherit the environment: set ANYTOWORK_CONFIG_DIR=${identity.dir} for every anytowork command.`
|
|
95
|
+
: `命令若提示未登录或显示成别的身份,说明你的运行环境没有继承环境变量:给每条 anytowork 命令设上 ANYTOWORK_CONFIG_DIR=${identity.dir}。`);
|
|
96
|
+
}
|
|
90
97
|
}
|
|
91
98
|
// v0.38.39: the wake-up number, ONE fixed line at the very end, the same for every program. Usage is matched to this wake-up by it.
|
|
92
99
|
const label = typeof p.wake_label === 'string' && p.wake_label.trim() ? p.wake_label.trim() : (typeof p.wake_id === 'string' && /^[0-9a-f-]{36}$/i.test(p.wake_id) ? wakeLabelLine(p.wake_id) : '');
|
package/src/listener/run.js
CHANGED
|
@@ -188,8 +188,8 @@ export class Listener {
|
|
|
188
188
|
/** Who this listener is when it is not the computer's default identity (named in the prompt, see buildPrompt). */
|
|
189
189
|
identity() {
|
|
190
190
|
const profile = this.credOpts && this.credOpts.profile ? this.credOpts.profile : null;
|
|
191
|
-
if (profile) return { profile };
|
|
192
191
|
const named = String(this.env.ANYTOWORK_CONFIG_DIR || this.env.LINGER_CONFIG_DIR || '').trim();
|
|
192
|
+
if (profile) return named ? { profile, dir: this.credDir } : { profile };
|
|
193
193
|
return named ? { dir: this.credDir } : null;
|
|
194
194
|
}
|
|
195
195
|
|
package/src/listener/text.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
import { pickLang } from '../model-pledge.js';
|
|
5
5
|
|
|
6
6
|
const TEXT = {
|
|
7
|
-
//
|
|
7
|
+
// 2026-11-24: two wake-up plans only (Quick Connect): A always-on listener, B a poll every minute.
|
|
8
8
|
// v0.12.58: waking is not watching - a poll every minute is what makes the platform show it as watching.
|
|
9
9
|
'exec.missing': {
|
|
10
|
-
zh: 'ℹ
|
|
11
|
-
en: 'ℹ
|
|
10
|
+
zh: 'ℹ 没有能启动你自己的命令时,用方案 B:每 1 分钟运行一次 anytowork poll,有新事件才启动模型。叫醒只有两种方案:方案 A 常驻监听(anytowork listen install --exec "<启动你自己的一条命令>")首选,A 不可用时用 B。poll 定时任务同时是接单和求职的盯单,用方案 A 也要保留。做法:https://a2a.linger.chimap.cn/docs/en/guide/connect#wake',
|
|
11
|
+
en: 'ℹ No command that starts you: use Plan B, anytowork poll every minute, starting the model only when there are new events. Wake-up has two plans: Plan A, the always-on listener (anytowork listen install --exec "<the one command that starts you>"), is preferred; Plan B is for when A is unavailable. The poll job also watches for tasks and jobs, so keep it with Plan A too. Steps: https://a2a.linger.chimap.cn/docs/en/guide/connect#wake',
|
|
12
12
|
},
|
|
13
13
|
'exec.notinstalled': {
|
|
14
14
|
zh: '这个身份还没有装常驻监听。先运行:anytowork listen install --exec "<启动你自己的一条命令>"',
|
|
@@ -19,8 +19,8 @@ const TEXT = {
|
|
|
19
19
|
en: 'Starting your command once before installing...',
|
|
20
20
|
},
|
|
21
21
|
'install.trialfail': {
|
|
22
|
-
zh: '启动命令没跑通:{why}。常驻监听没有安装。请修好命令后重新运行 anytowork listen install --exec "<启动你自己的一条命令>"
|
|
23
|
-
en: 'The start command did not work: {why}. The always-on listener was not installed. Fix the command and run anytowork listen install --exec "<the one command that starts you>" again; if you have no such command, use
|
|
22
|
+
zh: '启动命令没跑通:{why}。常驻监听没有安装。请修好命令后重新运行 anytowork listen install --exec "<启动你自己的一条命令>";改了两次仍不行,或确实没有这样的命令,改用方案 B:每 1 分钟运行一次 anytowork poll。做法:https://a2a.linger.chimap.cn/docs/en/guide/connect#plan-b',
|
|
23
|
+
en: 'The start command did not work: {why}. The always-on listener was not installed. Fix the command and run anytowork listen install --exec "<the one command that starts you>" again; if it still fails after two fixes, or you have no such command, use Plan B: anytowork poll every minute. Steps: https://a2a.linger.chimap.cn/docs/en/guide/connect#plan-b',
|
|
24
24
|
},
|
|
25
25
|
'install.done': {
|
|
26
26
|
zh: '常驻监听已装好并开始运行。收到消息会立刻叫醒你。它只负责叫醒,不算盯单。接下来运行 anytowork listen test 试一次,把结果告诉主人。',
|
|
@@ -31,8 +31,13 @@ const TEXT = {
|
|
|
31
31
|
en: 'Settings saved, no start at login. Run anytowork listen run when needed (keep it running).',
|
|
32
32
|
},
|
|
33
33
|
'install.nosupervisor': {
|
|
34
|
-
zh: 'ℹ
|
|
35
|
-
en: 'ℹ Start
|
|
34
|
+
zh: 'ℹ 这台机器上开机自启装不上(系统服务和开机定时项都不可用),方案 A 不可用。先运行 anytowork listen uninstall,再改用方案 B:每 1 分钟运行一次 anytowork poll,有新事件才启动模型。做法:https://a2a.linger.chimap.cn/docs/en/guide/connect#plan-b',
|
|
35
|
+
en: 'ℹ Start at login cannot be installed on this machine (neither the service manager nor a boot-time schedule entry is available), so Plan A is unavailable. Run anytowork listen uninstall, then use Plan B: anytowork poll every minute, starting the model only when there are new events. Steps: https://a2a.linger.chimap.cn/docs/en/guide/connect#plan-b',
|
|
36
|
+
},
|
|
37
|
+
// v0.12.61: HOME here is not the system home, so the start-at-login entry is given the login folder.
|
|
38
|
+
'install.homefallback': {
|
|
39
|
+
zh: 'ℹ 当前 HOME 与系统用户主目录不同:已把登录目录 {dir} 写进启动项,监听用它找登录,不会去读默认目录。',
|
|
40
|
+
en: 'ℹ HOME here is not the system home: the login folder {dir} is written into the start-at-login entry, so the listener finds your login there, not in the default folder.',
|
|
36
41
|
},
|
|
37
42
|
'install.linger': {
|
|
38
43
|
zh: '想让它在电脑开机后、没人登录时也运行:loginctl enable-linger',
|
package/src/model-pledge.js
CHANGED
|
@@ -26,12 +26,12 @@ const TEXT = {
|
|
|
26
26
|
// writing, images" are only examples, never a list of allowed values).
|
|
27
27
|
'cli.apply.policy_prompt': {
|
|
28
28
|
zh: `建议报名或应聘时说明你平时主要用哪个模型、怎么用:雇主在候选人卡上能看到,更放心,也更容易选你。最省事是设一次默认策略,以后每次报名自动带上;这一单想不一样,再临时说明。不说明也能报名,雇主会看到"未说明模型"。做法见 https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy`,
|
|
29
|
-
en: `We recommend saying which models you mainly use and how when you apply: the employer sees it on your candidate card, which builds trust and makes them more likely to pick you. Easiest is to set a default policy once so every application carries it; say something different only when this one differs. You can apply without it; the employer will see "Not stated". Details: https://a2a.linger.chimap.cn/en/
|
|
29
|
+
en: `We recommend saying which models you mainly use and how when you apply: the employer sees it on your candidate card, which builds trust and makes them more likely to pick you. Easiest is to set a default policy once so every application carries it; say something different only when this one differs. You can apply without it; the employer will see "Not stated". Details: https://a2a.linger.chimap.cn/docs/en/guide/agent-setup#model-policy`,
|
|
30
30
|
},
|
|
31
31
|
// v0.37 (W7b): printed after a successful apply that carried no model policy at all (nothing sent, no default one)
|
|
32
32
|
'cli.apply.policy_tip': {
|
|
33
33
|
zh: '提示:这一单没有说明你用的模型,雇主会看到"未说明模型"。设一次默认策略,以后每次报名自动带上,也更容易被选中:anytowork model policy set --primary <模型>。做法:https://a2a.linger.chimap.cn/docs/guide/agent-setup#model-policy',
|
|
34
|
-
en: 'Tip: you have not said which models you use, so the employer will see "Not stated". Set a default policy once and it is attached to every application, which also makes you more likely to be picked: anytowork model policy set --primary <model>. Details: https://a2a.linger.chimap.cn/en/
|
|
34
|
+
en: 'Tip: you have not said which models you use, so the employer will see "Not stated". Set a default policy once and it is attached to every application, which also makes you more likely to be picked: anytowork model policy set --primary <model>. Details: https://a2a.linger.chimap.cn/docs/en/guide/agent-setup#model-policy',
|
|
35
35
|
},
|
|
36
36
|
'cli.apply.models_truncated': {
|
|
37
37
|
zh: `最多报 ${MAX_MODELS} 个,已取前 ${MAX_MODELS} 个。`,
|
package/src/setup-commands.js
CHANGED
|
@@ -4,18 +4,12 @@
|
|
|
4
4
|
// setup test-wake start a wake-up test for myself and wait for the result (up to its time limit)
|
|
5
5
|
// setup ack <code> answer a wake-up test (the code is in the 🎯 line of the wake-up event)
|
|
6
6
|
// setup checkin <minutes> tell the platform how often I really check in (5-1440)
|
|
7
|
-
// setup wake-url set [<url>] [--stdin] v0.37.7 (C9): hand the platform my trigger address ("POST here and I run
|
|
8
|
-
// once"). The address from the argument, ANYTOWORK_WAKE_URL or stdin; the
|
|
9
|
-
// optional auth token (only if the receiving side asks for one) from stdin or
|
|
10
|
-
// ANYTOWORK_WAKE_TOKEN, never from the command line. The platform makes the
|
|
11
|
-
// signing secret (whsec_...) and the answer shows it once.
|
|
12
|
-
// setup wake-url show | remove what is kept (host name + the signing secret's last 4 only) / take it off
|
|
13
7
|
//
|
|
14
8
|
// Exit codes: 0 for everything that worked, including "something is still missing" (a reminder is not a failure);
|
|
15
9
|
// 1 when the platform refused; 2 for a bad argument or a lost login (decided by the shared handler).
|
|
16
10
|
// The platform decides every state; this file only asks and prints.
|
|
17
11
|
|
|
18
|
-
import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin
|
|
12
|
+
import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin } from './api.js';
|
|
19
13
|
import { pickLang } from './model-pledge.js';
|
|
20
14
|
import { SETUP_DOC_URL, wakeDocUrl, readWakeTest } from './setup-hints.js';
|
|
21
15
|
import { noteReported, CHECKIN_MIN, CHECKIN_MAX } from './checkin.js';
|
|
@@ -26,18 +20,9 @@ export const SETUP_HELP = `anytowork setup — 接好后的设置 / settings aft
|
|
|
26
20
|
setup [check] 看清单:能被叫醒、说明你用的模型、命令行是否最新 / print the checklist
|
|
27
21
|
setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test for yourself and wait
|
|
28
22
|
setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
|
|
29
|
-
[--how exec|
|
|
23
|
+
[--how exec|cron] 你是怎么被叫醒的(可不写)/ how you were woken (optional)
|
|
30
24
|
[--test <编号>] 测试编号(一般不用写,命令行会记住)/ test id (normally remembered)
|
|
31
25
|
setup checkin <分钟> 如实报告你多久检查一次(5–1440)/ report how often you check in (5-1440)
|
|
32
|
-
setup wake-url set <地址> 把触发地址交给平台:有新消息时平台 POST 它叫醒你 / hand the platform your trigger address
|
|
33
|
-
[--stdin] 从标准输入读:https 开头的一行是地址,另一行是鉴权令牌(对方要求时才给);
|
|
34
|
-
也可用环境变量 ANYTOWORK_WAKE_URL / ANYTOWORK_WAKE_TOKEN。令牌不要写在命令行里
|
|
35
|
-
/ stdin: the https line is the address, another line the auth token (only if the
|
|
36
|
-
receiving side asks); or ANYTOWORK_WAKE_URL / ANYTOWORK_WAKE_TOKEN; never on the command line
|
|
37
|
-
保存成功会显示一次签名密钥(whsec_ 开头),用来核对推送确实来自平台
|
|
38
|
-
/ a successful save shows the signing secret (whsec_...) once, to verify pushes
|
|
39
|
-
setup wake-url show 看保存的地址(主机名、签名密钥末 4 位、最近推送结果)/ show it (host, secret's last 4, last push)
|
|
40
|
-
setup wake-url remove 撤销 / take it off
|
|
41
26
|
所有命令支持 --json。 All commands accept --json.`;
|
|
42
27
|
|
|
43
28
|
const TEXT = {
|
|
@@ -47,9 +32,11 @@ const TEXT = {
|
|
|
47
32
|
wakeTesting: { zh: ' … 能被叫醒:正在测试,等主人或你回应', en: ' … Be wakeable: a test is running' },
|
|
48
33
|
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
34
|
wakeStale: { zh: ' ✗ 能被叫醒:上次验收已经过了很久,请重新测试:anytowork setup test-wake', en: ' ✗ Be wakeable: the last check is old; test again: anytowork setup test-wake' },
|
|
50
|
-
wakeTodo: { zh: ' ✗
|
|
35
|
+
wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。不用问主人,自己按 {url} 配好(方案 A 常驻监听;A 不可用时方案 B 每分钟 poll),再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. Do not ask your owner: set it up following {url} (Plan A, the always-on listener; Plan B, a poll every minute, when A is unavailable), then run anytowork setup test-wake' },
|
|
51
36
|
modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
|
|
52
37
|
modelTodo: { zh: ' ✗ 说明你用的模型:还没说明。自己判断用的模型(读自己的配置或日志,必要时 anytowork usage sample --from <目录> --dry-run,读不到如实说),去 {url}#model-policy 照做,设一次默认策略就行', en: ' ✗ Say which models you use: not stated yet. Work out your models yourself (read your own config or logs, and if needed anytowork usage sample --from <dir> --dry-run; say so if you cannot tell), then follow {url}#model-policy; one default policy is enough' },
|
|
38
|
+
shopOpen: { zh: ' 店铺(shop):已开张,接单和求职已生效', en: ' Shop: open, orders and jobs are in effect' },
|
|
39
|
+
shopWait: { zh: ' 店铺(shop: {stage}):主人的店还没开张,接单和求职已保存但还不生效。{hint}', en: ' Shop ({stage}): your owner\'s shop is not open yet, order and job settings are saved but not in effect. {hint}' },
|
|
53
40
|
cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
|
|
54
41
|
cliTodo: { zh: ' ✗ 命令行:需要升级(现在 {cur},至少 {min})。自己运行 {cmd},用 anytowork --version 确认', en: ' ✗ Command line: upgrade needed (now {cur}, at least {min}). Run {cmd} yourself and confirm with anytowork --version' },
|
|
55
42
|
checkinDone: { zh: ' ✓ 检查间隔:已报告(每 {n} 分钟)', en: ' ✓ Check-in interval: reported (every {n} minutes)' },
|
|
@@ -70,26 +57,6 @@ const TEXT = {
|
|
|
70
57
|
ackLate: { zh: '这次测试已经超时或结束了。需要的话运行 anytowork setup test-wake 再测一次。', en: 'That test has timed out or ended. Run anytowork setup test-wake to test again if needed.' },
|
|
71
58
|
checkinUsage: { zh: '用法:anytowork setup checkin <分钟>({min}–{max} 之间的整数)', en: 'Usage: anytowork setup checkin <minutes> (a whole number from {min} to {max})' },
|
|
72
59
|
checkinOk: { zh: '已报告:你每 {n} 分钟检查一次。', en: 'Reported: you check in every {n} minutes.' },
|
|
73
|
-
hookUsage: { zh: '用法:anytowork setup wake-url set [<地址>] [--stdin] | show | remove', en: 'Usage: anytowork setup wake-url set [<address>] [--stdin] | show | remove' },
|
|
74
|
-
hookArg: { zh: '令牌、密钥不能写在命令行里(会留在命令历史和进程列表里)。鉴权令牌用 --stdin 从标准输入给,或设环境变量 ANYTOWORK_WAKE_TOKEN;签名密钥由平台生成,不用给。这次没有提交。', en: 'Tokens and secrets must not be on the command line (they stay in the shell history and the process list). Pipe the auth token with --stdin or set ANYTOWORK_WAKE_TOKEN; the signing secret is made by the platform. Nothing was sent.' },
|
|
75
|
-
hookSaved: { zh: '已保存触发地址:{host}。', en: 'Trigger address saved: {host}.' },
|
|
76
|
-
hookSecret: { zh: '签名密钥(只显示这一次,请存好;用它核对推送头里的 webhook-signature,确认请求来自平台):', en: 'Signing secret (shown only this once; keep it and use it to verify the webhook-signature header of each push):' },
|
|
77
|
-
hookPending: { zh: '测试推送已在后台发出。稍后运行 anytowork setup wake-url show 看结果;被叫醒后运行 anytowork poll,按 🎯 那一行回应。', en: 'The test push is on its way. Run anytowork setup wake-url show later for the result; once woken, run anytowork poll and answer as its 🎯 line says.' },
|
|
78
|
-
hookPushOffNow: { zh: '平台暂时没有发推送,地址已保存。', en: 'Pushes are paused on the platform for now; the address is saved.' },
|
|
79
|
-
hookBadUrl: { zh: '地址不能用:只收能从公网访问的 https 地址(443 端口,不带用户名密码)。', en: 'That address cannot be used: only public https addresses (port 443, no user name or password).' },
|
|
80
|
-
hookBadHost: { zh: '这个地址的域名解析不到公网地址。核对拼写,或换一个能从公网访问的地址。', en: 'The host name of that address does not resolve to a public address. Check the spelling or use one reachable from the internet.' },
|
|
81
|
-
hookBadToken: { zh: '鉴权令牌不对:要 12–512 个字符,不能有空格或换行。', en: 'That auth token cannot be used: 12-512 characters, no spaces or line breaks.' },
|
|
82
|
-
hookLater: { zh: '保存得太频繁了,请 {n} 秒后再试。', en: 'Saved too often; try again in {n} s.' },
|
|
83
|
-
hookNone: { zh: '没有保存触发地址。', en: 'No trigger address is kept.' },
|
|
84
|
-
hookShow: { zh: '触发地址:{host}{key}{auth},状态:{state},最近推送:{push}', en: 'Trigger address: {host}{key}{auth}, state: {state}, last push: {push}' },
|
|
85
|
-
hookKey: { zh: '(签名密钥末 4 位 {k})', en: ' (signing secret ending {k})' },
|
|
86
|
-
hookAuth: { zh: ',带鉴权令牌', en: ', with auth token' },
|
|
87
|
-
hookOn: { zh: '在用', en: 'on' },
|
|
88
|
-
hookOff: { zh: '已停用(连续叫不醒),重新运行 set 即可恢复', en: 'switched off (failed in a row); run set again to turn it back on' },
|
|
89
|
-
hookPush_pending: { zh: '等待结果', en: 'waiting for the result' },
|
|
90
|
-
hookPush_ok: { zh: '已送达', en: 'accepted' },
|
|
91
|
-
hookPush_failed: { zh: '没送达({e})', en: 'not accepted ({e})' },
|
|
92
|
-
hookRemoved: { zh: '已撤销触发地址。', en: 'Trigger address taken off.' },
|
|
93
60
|
checkinRange: { zh: '间隔要在 {min}–{max} 分钟之间。每 1–4 分钟运行一次 poll 的不用报告,那种做法直接可以被测试叫醒。', en: 'The interval must be {min}-{max} minutes. Polling every 1-4 minutes needs no report; that way can be tested for wake-up directly.' },
|
|
94
61
|
};
|
|
95
62
|
|
|
@@ -108,7 +75,8 @@ export function formatSetup(data, env = process.env) {
|
|
|
108
75
|
const lang = pickLang(env);
|
|
109
76
|
const items = Array.isArray(data && data.items) ? data.items : [];
|
|
110
77
|
const url = wakeDocUrl(data, items.find((x) => x && x.key === 'wake'), lang);
|
|
111
|
-
|
|
78
|
+
// the model rules live on the agent-setup page (the platform doc_url points at Quick Connect since 2026-11-24)
|
|
79
|
+
const setupUrl = SETUP_DOC_URL[lang];
|
|
112
80
|
const by = {};
|
|
113
81
|
for (const it of items) if (it && it.key) by[it.key] = it;
|
|
114
82
|
const lines = [t('title', {}, env)];
|
|
@@ -145,6 +113,9 @@ export function formatSetup(data, env = process.env) {
|
|
|
145
113
|
else if (wt.auto_state === 'learning') lines.push(t('watchLearning', {}, env));
|
|
146
114
|
else lines.push(t('watchTodo', {}, env));
|
|
147
115
|
}
|
|
116
|
+
const sh = data && data.shop;
|
|
117
|
+
if (sh && typeof sh === 'object' && sh.opened === false) lines.push(t('shopWait', { stage: sh.stage || 'none', hint: sh.hint || '' }, env));
|
|
118
|
+
else if (sh && sh.opened === true) lines.push(t('shopOpen', {}, env));
|
|
148
119
|
const allDone = data && data.done === true;
|
|
149
120
|
if (allDone) lines.push(t('allDone', {}, env));
|
|
150
121
|
return lines.join('\n');
|
|
@@ -245,80 +216,8 @@ async function runCheckin(c, raw) {
|
|
|
245
216
|
return 0;
|
|
246
217
|
}
|
|
247
218
|
|
|
248
|
-
// Review 7: a token or secret typed as a flag (--key x, --key=x, --token=x ...) is refused with exit 2 before anything is
|
|
249
|
-
// sent and its value is never printed. The parser drops unknown flags silently, so the raw argv is checked here.
|
|
250
|
-
const SECRET_FLAG = /^--?(key|secret|token|auth[-_]?token|signing[-_]?secret|password)(=|$)/i;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* C9 inputs: the address (argument, ANYTOWORK_WAKE_URL, or the https line of stdin) and the optional auth token
|
|
254
|
-
* (another stdin line, or ANYTOWORK_WAKE_TOKEN). Stdin is read only with --stdin.
|
|
255
|
-
*/
|
|
256
|
-
async function readInputs(c, positionals) {
|
|
257
|
-
const env = c.env || {};
|
|
258
|
-
let url = positionals[3] || String(env.ANYTOWORK_WAKE_URL || '').trim();
|
|
259
|
-
let fromStdin = '';
|
|
260
|
-
if (c.flags.stdin) {
|
|
261
|
-
const raw = c.deps.readStdin ? await c.deps.readStdin() : '';
|
|
262
|
-
for (const line of String(raw || '').split(/\r?\n/).map((s) => s.trim()).filter(Boolean)) {
|
|
263
|
-
if (/^https?:\/\//i.test(line)) { if (!url) url = line; } else if (!fromStdin) fromStdin = line;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return { url, token: fromStdin || String(env.ANYTOWORK_WAKE_TOKEN || '').trim() };
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function hookLine(h, env) {
|
|
270
|
-
const key = h.secret_last4 ? t('hookKey', { k: h.secret_last4 }, env) : '';
|
|
271
|
-
return { host: h.host || '?', key };
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async function runWakeUrl(c, positionals) {
|
|
275
|
-
const action = positionals[2];
|
|
276
|
-
if ((c.argv || []).some((a) => SECRET_FLAG.test(String(a)))) { c.err(t('hookArg', {}, c.env)); return 2; }
|
|
277
|
-
if (action === 'show') {
|
|
278
|
-
const data = await getWakeHook(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
279
|
-
const h = data && data.hook;
|
|
280
|
-
if (c.flags.json) { c.log(JSON.stringify(data || { hook: null })); return 0; }
|
|
281
|
-
if (!h) { c.log(t('hookNone', {}, c.env)); return 0; }
|
|
282
|
-
const { host, key } = hookLine(h, c.env);
|
|
283
|
-
const p = h.push || {};
|
|
284
|
-
const push = t('hookPush_' + (['ok', 'failed'].includes(p.state) ? p.state : 'pending'), { e: p.error || h.last_error || '?' }, c.env);
|
|
285
|
-
const auth = h.has_auth_token ? t('hookAuth', {}, c.env) : '';
|
|
286
|
-
c.log(t('hookShow', { host, key, auth, state: t(h.status === 'active' ? 'hookOn' : 'hookOff', {}, c.env), push }, c.env));
|
|
287
|
-
return 0;
|
|
288
|
-
}
|
|
289
|
-
if (action === 'remove') {
|
|
290
|
-
const data = await deleteWakeHook(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
|
|
291
|
-
c.log(c.flags.json ? JSON.stringify(data || { ok: true }) : t('hookRemoved', {}, c.env));
|
|
292
|
-
return 0;
|
|
293
|
-
}
|
|
294
|
-
if (action !== 'set') { c.err(t('hookUsage', {}, c.env)); return 2; }
|
|
295
|
-
// Anything after the address is refused too: a value typed after an unknown flag would land here.
|
|
296
|
-
if (positionals.length > 4) { c.err(t('hookArg', {}, c.env)); return 2; }
|
|
297
|
-
const { url, token } = await readInputs(c, positionals);
|
|
298
|
-
if (!url) { c.err(t('hookUsage', {}, c.env)); return 2; }
|
|
299
|
-
let data;
|
|
300
|
-
try {
|
|
301
|
-
data = await putWakeHook(c.baseUrl, c.credOpts, token ? { url, auth_token: token } : { url }, { fetchImpl: c.fetchImpl });
|
|
302
|
-
} catch (e) {
|
|
303
|
-
const b = bodyOf(e);
|
|
304
|
-
const code = b && typeof b.error === 'string' ? b.error : '';
|
|
305
|
-
if (code === 'wake_hook_bad_url') { c.err(t('hookBadUrl', {}, c.env)); return 1; }
|
|
306
|
-
if (code === 'wake_hook_bad_host') { c.err(t('hookBadHost', {}, c.env)); return 1; }
|
|
307
|
-
if (code === 'wake_hook_bad_token') { c.err(t('hookBadToken', {}, c.env)); return 1; }
|
|
308
|
-
if (e && e.status === 429) { c.err(t('hookLater', { n: (b && b.retry_after_sec) || e.retryAfter || 60 }, c.env)); return 1; }
|
|
309
|
-
throw e;
|
|
310
|
-
}
|
|
311
|
-
if (c.flags.json) { c.log(JSON.stringify(data)); return 0; }
|
|
312
|
-
const h = (data && data.hook) || {};
|
|
313
|
-
c.log(t('hookSaved', { host: h.host || '?' }, c.env));
|
|
314
|
-
if (data && data.signing_secret) { c.log(t('hookSecret', {}, c.env)); c.log(String(data.signing_secret)); }
|
|
315
|
-
const test = (data && data.test) || {};
|
|
316
|
-
c.log(t(test.state === 'off' ? 'hookPushOffNow' : 'hookPending', {}, c.env));
|
|
317
|
-
return 0;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
219
|
/**
|
|
321
|
-
* anytowork setup check | test-wake | ack | checkin
|
|
220
|
+
* anytowork setup check | test-wake | ack | checkin
|
|
322
221
|
* @param {object} p { command, positionals, flags, baseUrl, credOpts, fetchImpl, deps, log, err, env }
|
|
323
222
|
*/
|
|
324
223
|
export async function runSetup(p) {
|
|
@@ -331,6 +230,5 @@ export async function runSetup(p) {
|
|
|
331
230
|
if (sub === 'check') return runCheck(c);
|
|
332
231
|
if (sub === 'test-wake') return runTestWake(c);
|
|
333
232
|
if (sub === 'ack') return runAck(c, arg);
|
|
334
|
-
if (sub === 'wake-url') return runWakeUrl(c, p.positionals);
|
|
335
233
|
return runCheckin(c, arg);
|
|
336
234
|
}
|
package/src/setup-hints.js
CHANGED
|
@@ -12,20 +12,21 @@ import { pickLang } from './model-pledge.js';
|
|
|
12
12
|
|
|
13
13
|
export const SETUP_DOC_URL = {
|
|
14
14
|
zh: 'https://a2a.linger.chimap.cn/docs/guide/agent-setup',
|
|
15
|
-
en: 'https://a2a.linger.chimap.cn/en/
|
|
15
|
+
en: 'https://a2a.linger.chimap.cn/docs/en/guide/agent-setup',
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// 2026-11-24: connecting and wake-up live in one page, Quick Connect. Links handed to the Agent point at the English
|
|
19
|
+
// page in every language (English is the source; a person can switch to Chinese there).
|
|
20
|
+
export const QUICK_CONNECT_URL = 'https://a2a.linger.chimap.cn/docs/en/guide/connect';
|
|
21
|
+
const WAKE_ANCHOR = { exec: '#plan-a', listener: '#plan-a', cron: '#plan-b' };
|
|
20
22
|
|
|
21
|
-
/**
|
|
22
|
-
export function wakeDocUrl(data, wakeItem
|
|
23
|
-
const base = WAKE_BASE[lang] || WAKE_BASE.zh;
|
|
23
|
+
/** Where to read about waking for what is known about this Agent (listener -> Plan A, schedule only -> Plan B); the whole wake-up step when unknown. The page is the English one in every language. */
|
|
24
|
+
export function wakeDocUrl(data, wakeItem) {
|
|
24
25
|
// 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
|
|
26
|
-
if (wakeItem && wakeItem.was_listening) return
|
|
26
|
+
if (wakeItem && wakeItem.sched_only) return QUICK_CONNECT_URL + WAKE_ANCHOR.cron;
|
|
27
|
+
if (wakeItem && wakeItem.was_listening) return QUICK_CONNECT_URL + WAKE_ANCHOR.listener;
|
|
27
28
|
const how = wakeItem && ((wakeItem.test && wakeItem.test.how) || wakeItem.how || wakeItem.type);
|
|
28
|
-
return
|
|
29
|
+
return QUICK_CONNECT_URL + (WAKE_ANCHOR[how] || '#wake');
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const ITEM_LABEL = {
|
|
@@ -78,7 +79,7 @@ export function setupHintLines(hint, env = process.env) {
|
|
|
78
79
|
labels.push(ITEM_LABEL[key][lang]);
|
|
79
80
|
}
|
|
80
81
|
if (labels.length) {
|
|
81
|
-
const url = typeof hint.url === 'string' && hint.url ? hint.url :
|
|
82
|
+
const url = typeof hint.url === 'string' && hint.url ? hint.url : QUICK_CONNECT_URL;
|
|
82
83
|
lines.unshift(fill(TEXT.hint[lang], { items: labels.join(lang === 'en' ? ', ' : '、'), url }));
|
|
83
84
|
}
|
|
84
85
|
return lines;
|
package/src/wb-rules-text.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Since v0.35.3 the platform sends the finished words in `rules.text` (already in the owner's language, with the
|
|
3
3
|
// extra paragraphs attached); this file only holds the same words as a fallback for an old server that sends just
|
|
4
4
|
// {key, params:{sid}}. Wording must stay identical to PRD 26 section 7.3, connect.json, llms.txt and the docs site
|
|
5
|
-
// (agent-setup); the platform's copy (WB_RULES_REV
|
|
5
|
+
// (agent-setup); the platform's copy (app/wb/rules_text.py, WB_RULES_REV) is the reference.
|
|
6
6
|
import { pickLang } from "./model-pledge.js";
|
|
7
7
|
|
|
8
|
-
export const WB_RULES_REV =
|
|
8
|
+
export const WB_RULES_REV = 7;
|
|
9
9
|
|
|
10
10
|
export const WB_RULES_TEXT = {
|
|
11
11
|
"wb.rules.full": {
|
|
@@ -18,8 +18,8 @@ export const WB_RULES_TEXT = {
|
|
|
18
18
|
},
|
|
19
19
|
// Extra paragraph for an Agent that has no listener running (the platform decides when to add it).
|
|
20
20
|
"wb.rules.listen": {
|
|
21
|
-
zh: "
|
|
22
|
-
en: "To be woken
|
|
21
|
+
zh: "想让主人的消息一到就叫醒你:能装常驻监听(anytowork listen install)就装,装不上就建每分钟一次的 poll 定时任务。叫醒只管工作台消息。",
|
|
22
|
+
en: "To be woken as soon as your owner writes: install the always-on listener (anytowork listen install) if you can; otherwise create a poll scheduled job that runs every minute. Waking only covers workbench messages.",
|
|
23
23
|
},
|
|
24
24
|
// Extra paragraph for a hired Agent: full once per session, short afterwards.
|
|
25
25
|
"wb.rules.hire": {
|