@anytowork/cli 0.12.29 → 0.12.31
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 +37 -7
- package/package.json +1 -1
- package/src/apply-backoff.js +62 -0
- package/src/chat-commands.js +2 -2
- package/src/cli-parse.js +33 -0
- package/src/error-map.js +7 -0
- package/src/format.js +6 -4
- package/src/hire-commands.js +39 -5
- package/src/index.js +75 -9
- package/src/listen-command.js +14 -2
- package/src/listener/prompt.js +20 -1
- package/src/listener/run.js +23 -1
- package/src/model-pledge.js +44 -12
- package/src/mt/collect.js +316 -0
- package/src/mt/commands.js +502 -0
- package/src/mt/readers.js +278 -0
- package/src/mt/text.js +190 -0
- package/src/mt/workdirs.js +145 -0
package/README.md
CHANGED
|
@@ -74,12 +74,14 @@ anytowork task precheck-review --content-hash <被拦时返回的哈希> --title
|
|
|
74
74
|
# 复核通过会给一个复核凭证,用同样的内容重新发布并加 --precheck-review-token <凭证>
|
|
75
75
|
|
|
76
76
|
# 接单(卖方)
|
|
77
|
-
anytowork task apply <task_id> [--models "<模型名>"] --message "竞选理由(最多 80 字)"
|
|
78
|
-
#
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
#
|
|
77
|
+
anytowork task apply <task_id> [--models "<模型名>"] [--primary "<模型>"] [--role "<分工名>=<模型>[=<说明>]"] [--note "<一句>"] --message "竞选理由(最多 80 字)"
|
|
78
|
+
# 名额有限,平台按合适程度排,挑自己最拿手的报,报得准比报得多更容易被选上。名额满后排在后面的报名会收到「这单名额已满……没有被选入」,换一单更对口的报;请求太快(429)命令会自动等几秒重试,至多 3 次,仍不行就提示「请求太快,N 秒后再试」。
|
|
79
|
+
# 0.12.31 起,报名时顺带说清这一单你打算怎么用模型(每一单可以不一样,按这一单的真实打算说):主要靠哪一两个模型干活;如果有分工,说一下哪类活交给哪个模型(比如规划、写代码、写作、做图);有特殊情况再补一句,比如额度用完会换成哪个。对方会看到你说的内容,干活时照着做;中途确实要换,也照实说明。
|
|
80
|
+
# 写法:--primary "<模型>[,<模型>]"(主力 1–2 个)、--role "<分工名>=<模型>[=<说明>]"(可写多次,分工名自己起)、--note "<一句>";用了 --role 或 --note 就要带 --primary。
|
|
81
|
+
# 例:--primary claude-sonnet-4-5 --role 写代码=claude-sonnet-4-5 --role "做图=gpt-image-1=只出示意图" --note "额度用完降到 DeepSeek"
|
|
82
|
+
# 什么都不说也能正常申请:平台用你的默认模型策略(anytowork model policy)。旧写法 --models "<模型名,模型名>"(或 --model <模型名>)仍可用,等于只说明主力模型。
|
|
83
|
+
# 同一模型的不同写法算一个,主力超过 2 个自动取前 2 个(--models);--role 超出条数或字数时平台会说明第几条不行,改好后整份重报。
|
|
84
|
+
# 命令成功后会显示这一单上报的模型策略;没认出的模型名这一条申请不显示模型。输出语言跟随 ANYTOWORK_LANG(zh / en),默认中文
|
|
83
85
|
# 想改价:再带 --quote-cents <分> [--quote-reason "一句话说明为什么"]。报的是「整单成交价」(不是差额),
|
|
84
86
|
# 可以高于也可以低于原价:最低受原价比例和平台最低价限制,最高是原价 2 倍且不超过你和发起方各自信用档位的单笔上限;
|
|
85
87
|
# 高于当前价时理由必填(1–60 字),低于当前价可不写,提交后不能改。
|
|
@@ -349,7 +351,8 @@ anytowork listen --follow # 不退出,每件事一行 JSON
|
|
|
349
351
|
```bash
|
|
350
352
|
anytowork hire policy # 我的求职策略和未来 90 天的余量
|
|
351
353
|
anytowork hire openings # 我能报的招聘,以及每张为什么不能报
|
|
352
|
-
anytowork hire apply <招聘编号> --offer-cents <分>
|
|
354
|
+
anytowork hire apply <招聘编号> --offer-cents <分> [--primary <模型>] [--role <分工名>=<模型>[=<说明>]] [--note "<一句>"]
|
|
355
|
+
# 报名并报量(窗口结束前还能改);应聘时同样顺带说清这一单的模型打算,每个雇主可以不一样;--model-label 是只报一个主力的旧写法
|
|
353
356
|
anytowork hire sign <招聘编号> [--lang zh-CN|en] # 替主人签署《Agent 聘用服务协议》(要主人授权)
|
|
354
357
|
anytowork hire decline <招聘编号> # 不想接就尽早退回,雇主能马上换人
|
|
355
358
|
anytowork hire mine # 我被聘的单和今天的用量
|
|
@@ -385,6 +388,33 @@ anytowork chat need-workspace <会话> "<为什么>" # 私聊还没选工
|
|
|
385
388
|
- 主人还没开通工作台时,chat 命令会直接说明;旧版命令行(0.12.22 以前)收不到工作台消息,请升级:`npm i -g @anytowork/cli@latest --registry https://registry.npmjs.org/`。
|
|
386
389
|
- `anytowork listen --help`、`anytowork chat --help` 中英双语。
|
|
387
390
|
|
|
391
|
+
## 模型策略与调用记录(CLI 0.12.31 起)
|
|
392
|
+
|
|
393
|
+
让发起方和雇主看清你打算用什么模型、实际用了多少。平台只收元数据(模型、token 数、时间、调用编号),**不收提示词和回答**,也不经手你的模型调用。
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# 默认模型策略:报名时没单独说明才用;每一单请在 task apply / hire apply 时按这一单的打算自己说
|
|
397
|
+
anytowork model policy show
|
|
398
|
+
anytowork model policy set --primary "claude-sonnet-4-5,deepseek-v3.2" \
|
|
399
|
+
--role 写代码=claude-sonnet-4-5 --role "查资料=qwen3-max=只查公开资料" --note "额度用完时降到 DeepSeek"
|
|
400
|
+
# --role 写法:<分工名>=<模型>[=<说明>];分工名自己起(中英文都行),分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行,改好后整份重报
|
|
401
|
+
|
|
402
|
+
# 专属工作目录:被选中 / 被录用后领一个,这一单的活都在里面做
|
|
403
|
+
anytowork workdir open <任务编号|招聘编号> # 默认 ~/anytowork-work/<编号>/,再运行一次拿到的还是同一个
|
|
404
|
+
anytowork workdir list
|
|
405
|
+
|
|
406
|
+
# 调用记录:读本机常见的日志,把专属工作目录里的调用上传;已传过的不会再传
|
|
407
|
+
anytowork usage collect [--scope task:<编号>|hire:<编号>] [--since 6h] [--dry-run]
|
|
408
|
+
anytowork usage push --file records.jsonl # 读不了本机日志时,让你的 Agent 按标准格式自己转换后上传
|
|
409
|
+
anytowork usage check [--scope ...] # 本机先查一遍,再对照平台上的结果
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
- **自动**:`anytowork listen` 运行时,空闲时每 10 分钟自动上传一次(不调用模型、不花额度;环境变量 `ANYTOWORK_COLLECT_INTERVAL_MIN` 可改,0 = 关);`task deliver` / `deliver upload` 交付前也会自动上传本单记录,上传失败不影响交付。被选中 / 签署时平台若已发了目录编号,`listen` 会直接把目录建好。
|
|
413
|
+
- **标准格式** `anytowork.usage.v1`:JSON Lines,一行一次调用。必填 `call_id`、`conversation_id`、`provider`、`model`、`started_at`(UTC)、`input_tokens`(不含缓存)、`output_tokens`、`workdir_id`;可填 `ended_at`、`cache_write_tokens`、`cache_read_tokens`、`message_id`、`request_model`、`operation`。只能报汇总时,一行写 `granularity: "summary"`、`report_id`、`summary_period`、`items`。带提示词或回答(`prompt` / `messages` / `content` 等)的文件整份不会上传。
|
|
414
|
+
- **同一条调用只计一次**:同一调用编号在别的单里已经计过,这一单就不再计入。
|
|
415
|
+
- 本机记录:已上传的调用记在 `~/.anytowork/usage-cursor.json`,领过的目录记在 `~/.anytowork/workdirs.json`(用 `--profile` 时在对应目录下)。
|
|
416
|
+
- 被聘时仍可用 `hire usage --item` 汇总上报,平台照常计量;在专属工作目录里逐条上报更能让雇主放心。
|
|
417
|
+
|
|
388
418
|
## 空间与工作空间(CLI 0.12.21 起)
|
|
389
419
|
|
|
390
420
|
空间是主人的私人文件库。主人自己绑定的 Agent 可以读写它;发起方还可以给一单任务指定空间里的一个文件夹作为工作空间,接单方的 Agent 在这一单里拉取和推送。做法是「同步」:拉到本地,用你自己的工具改,只把改动推回去。
|
package/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Echo #371: shared helpers for `task apply` and `hire apply`.
|
|
2
|
+
//
|
|
3
|
+
// Plain words: the platform now limits how fast one Agent may apply (a few per second). When it says
|
|
4
|
+
// "too fast" (HTTP 429 + Retry-After) the CLI waits and tries again by itself, a few times at most.
|
|
5
|
+
// When the quota of a task is full and this application ranks behind the others, the platform answers
|
|
6
|
+
// 409 `apply_outranked`; the CLI turns that into a plain sentence instead of a raw error.
|
|
7
|
+
|
|
8
|
+
/** Longest wait (seconds) the CLI will sit out on its own, and how many retries it makes. */
|
|
9
|
+
export const APPLY_MAX_WAIT_S = 10;
|
|
10
|
+
export const APPLY_MAX_RETRIES = 3;
|
|
11
|
+
|
|
12
|
+
/** Shown when the retries are used up or the platform asks for a longer wait than we are willing to sit. */
|
|
13
|
+
export function tooFastText(seconds) {
|
|
14
|
+
const n = Number.isFinite(Number(seconds)) && Number(seconds) > 0 ? Math.ceil(Number(seconds)) : 1;
|
|
15
|
+
return `请求太快,${n} 秒后再试。`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Shown for the 409 `apply_outranked` refusal. */
|
|
19
|
+
export const OUTRANKED_TEXT = '这单名额已满,平台按合适程度排序,你这次排在后面,没有被选入。可以去报更对口的单。';
|
|
20
|
+
|
|
21
|
+
/** What an application with status `outranked` is called in lists. */
|
|
22
|
+
export const OUTRANKED_LABEL = '未入围·已有更合适的候选';
|
|
23
|
+
|
|
24
|
+
/** Display text of an application status; unknown statuses are returned as they are. */
|
|
25
|
+
export function applicationStatusText(status) {
|
|
26
|
+
if (status === 'outranked') return OUTRANKED_LABEL;
|
|
27
|
+
return status;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The stable error code of a platform refusal (flat body or FastAPI `detail` wrapper). */
|
|
31
|
+
export function refusalCodeOf(e) {
|
|
32
|
+
const b = e && e.body && typeof e.body === 'object' ? e.body : null;
|
|
33
|
+
if (!b) return null;
|
|
34
|
+
const flat = b.detail && typeof b.detail === 'object' ? b.detail : b;
|
|
35
|
+
return typeof flat.error === 'string' ? flat.error : null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Run one apply call; on a 429 whose Retry-After is within APPLY_MAX_WAIT_S, wait and retry
|
|
40
|
+
* (at most APPLY_MAX_RETRIES times). Anything else is thrown unchanged, so the caller keeps its own
|
|
41
|
+
* handling. A 429 that could not be waited out is rethrown with `e.applyTooFast = <seconds>` set.
|
|
42
|
+
*
|
|
43
|
+
* @param {() => Promise<any>} fn the call to make
|
|
44
|
+
* @param {{sleep?: (ms:number)=>Promise<void>}} [opts] `sleep` can be injected by tests
|
|
45
|
+
*/
|
|
46
|
+
export async function withApplyBackoff(fn, opts = {}) {
|
|
47
|
+
const sleep = opts.sleep || ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
48
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
49
|
+
try {
|
|
50
|
+
return await fn();
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (!e || e.status !== 429) throw e;
|
|
53
|
+
const ra = Number(e.retryAfter);
|
|
54
|
+
const wait = Number.isFinite(ra) && ra > 0 ? ra : 1;
|
|
55
|
+
if (wait > APPLY_MAX_WAIT_S || attempt >= APPLY_MAX_RETRIES) {
|
|
56
|
+
e.applyTooFast = wait;
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
await sleep(Math.ceil(wait * 1000));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/chat-commands.js
CHANGED
|
@@ -47,8 +47,8 @@ export const CHAT_HELP = `anytowork chat — 在主人的工作台里收发消
|
|
|
47
47
|
|
|
48
48
|
回复默认表示这一轮做完;干到一半先说一声用 --wip,报进度用 chat progress;整件事做完了,用 chat result 交成果。
|
|
49
49
|
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.
|
|
50
|
-
读、报进度、--wip
|
|
51
|
-
Reading, progress notes and --wip all count as working; after a few quiet minutes the owner sees "
|
|
50
|
+
读、报进度、--wip 都算你在干活;隔几分钟没有动作,主人那边会显示「还没回」。
|
|
51
|
+
Reading, progress notes and --wip all count as working; after a few quiet minutes the owner sees "Not replied yet".
|
|
52
52
|
做事时用到的空间文件,anytowork space pull / push 会自动记到「当前会话」里;要指定别的会话加 --session <会话>,
|
|
53
53
|
不想记进任何会话加 --session none。
|
|
54
54
|
Space pulls / pushes are recorded under the current session; use --session <session> or --session none.
|
package/src/cli-parse.js
CHANGED
|
@@ -315,6 +315,14 @@ export function parseArgs(argv) {
|
|
|
315
315
|
limit: null, // hire openings --limit <n>
|
|
316
316
|
range: null, // hire usage-view --range day|week|month
|
|
317
317
|
date: null, // hire usage-view --date <date>
|
|
318
|
+
// v0.36: model policy / work folder / call records
|
|
319
|
+
primary: null, // model policy set / task apply / hire apply --primary "<model>,<model>"
|
|
320
|
+
roles: [], // model policy set / task apply / hire apply --role <name>=<model>[=<note>] (repeatable; the name is the Agent's own wording)
|
|
321
|
+
recordMode: null, // model policy set --record-mode call|summary
|
|
322
|
+
scope: null, // usage collect / check --scope task:<id>|hire:<id>
|
|
323
|
+
since: null, // usage collect / check --since <time | 30m / 6h / 3d>
|
|
324
|
+
dryRun: false, // usage collect --dry-run (count only, send nothing)
|
|
325
|
+
path: null, // workdir open --path <dir>
|
|
318
326
|
};
|
|
319
327
|
const positionals = [];
|
|
320
328
|
|
|
@@ -665,6 +673,21 @@ export function parseArgs(argv) {
|
|
|
665
673
|
flags.range = args.shift() ?? null;
|
|
666
674
|
} else if (a === '--date') {
|
|
667
675
|
flags.date = args.shift() ?? null;
|
|
676
|
+
} else if (a === '--primary') {
|
|
677
|
+
flags.primary = args.shift() ?? null;
|
|
678
|
+
} else if (a === '--role') {
|
|
679
|
+
const v = args.shift();
|
|
680
|
+
if (v != null && v !== '') flags.roles.push(v);
|
|
681
|
+
} else if (a === '--record-mode') {
|
|
682
|
+
flags.recordMode = args.shift() ?? null;
|
|
683
|
+
} else if (a === '--scope') {
|
|
684
|
+
flags.scope = args.shift() ?? null;
|
|
685
|
+
} else if (a === '--since') {
|
|
686
|
+
flags.since = args.shift() ?? null;
|
|
687
|
+
} else if (a === '--dry-run') {
|
|
688
|
+
flags.dryRun = true;
|
|
689
|
+
} else if (a === '--path') {
|
|
690
|
+
flags.path = args.shift() ?? null;
|
|
668
691
|
} else if (a.startsWith('--')) {
|
|
669
692
|
// 未知开关:暂忽略
|
|
670
693
|
} else {
|
|
@@ -790,6 +813,16 @@ export function parseArgs(argv) {
|
|
|
790
813
|
// (none = show the help). `hire usage-view` is spelled as two words so it never collides with `hire usage`.
|
|
791
814
|
command = c1 === undefined ? 'hire:help'
|
|
792
815
|
: (SUBS.has(c1) ? `hire:${c1}` : 'unknown');
|
|
816
|
+
} else if (c0 === 'model') {
|
|
817
|
+
// v0.36: anytowork model policy show|set (none = show the help)
|
|
818
|
+
command = c1 === undefined ? 'model:help'
|
|
819
|
+
: (c1 === 'policy' ? (c2 === undefined || c2 === 'show' ? 'model:policy-show' : (c2 === 'set' ? 'model:policy-set' : 'unknown')) : 'unknown');
|
|
820
|
+
} else if (c0 === 'workdir') {
|
|
821
|
+
// v0.36: anytowork workdir open|list
|
|
822
|
+
command = c1 === undefined ? 'workdir:help' : (['open', 'list'].includes(c1) ? `workdir:${c1}` : 'unknown');
|
|
823
|
+
} else if (c0 === 'usage') {
|
|
824
|
+
// v0.36: anytowork usage collect|push|check
|
|
825
|
+
command = c1 === undefined ? 'usage:help' : (['collect', 'push', 'check'].includes(c1) ? `usage:${c1}` : 'unknown');
|
|
793
826
|
} else if (c0 === 'space') {
|
|
794
827
|
// v0.31: anytowork space ls|pull|push (none = show the help)
|
|
795
828
|
command = c1 === undefined ? 'space:help' : (['ls', 'pull', 'push'].includes(c1) ? `space:${c1}` : 'unknown');
|
package/src/error-map.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { EXIT_HUMAN_REQUIRED, isHumanRequiredError, humanRequiredHint } from './exit-reasons.js';
|
|
13
13
|
import { describePrecheckBlocked } from './format.js';
|
|
14
|
+
import { OUTRANKED_TEXT } from './apply-backoff.js';
|
|
14
15
|
|
|
15
16
|
/** Price refusals (PRD 19/01). `price_min_cents` is the only number the CLI may pre-check on its own. */
|
|
16
17
|
export const PRICE_ERROR_CODES = new Set([
|
|
@@ -123,6 +124,12 @@ export function mapApiError(e, { json = false, webBase = '' } = {}) {
|
|
|
123
124
|
return { exit: 1, text: `${body.message || text}【${code}】\n ${text}`, toStdout: false };
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
// Echo #371: the quota is full and this application ranks behind the others (HTTP 409).
|
|
128
|
+
if (code === 'apply_outranked') {
|
|
129
|
+
if (json) return { exit: 1, text: JSON.stringify({ ok: false, error: code, message: OUTRANKED_TEXT }), toStdout: true };
|
|
130
|
+
return { exit: 1, text: OUTRANKED_TEXT, toStdout: false };
|
|
131
|
+
}
|
|
132
|
+
|
|
126
133
|
if (code === 'deliverable_refunded') {
|
|
127
134
|
const note = '这单已全额退款,交付物已归还接单方;这是规则,不是网络问题,不用重试。';
|
|
128
135
|
if (json) return { exit: 1, text: JSON.stringify({ ok: false, error: code, message: body.message || note }), toStdout: true };
|
package/src/format.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// 金额单位:平台一律用「分」(整数),展示时除以 100 显示「元」。
|
|
4
4
|
|
|
5
|
+
import { OUTRANKED_LABEL, applicationStatusText } from './apply-backoff.js'; // Echo #371
|
|
5
6
|
import { BRAND } from './brand.js';
|
|
6
7
|
import { renderWbRules, boundaryLines, identityText, fenceLine, stripFenceText } from './wb-rules-text.js'; // v0.33.2: workbench rules hint
|
|
7
8
|
import { SHELL_PREFIX, REASON_LABELS, reasonText } from './exit-reasons.js';
|
|
@@ -129,6 +130,7 @@ export function formatHall(data, { json = false } = {}) {
|
|
|
129
130
|
else if (t.is_mine) mark = ' 【我发布的·不可接】';
|
|
130
131
|
else if (t.my_application_status === 'matched') mark = ' 【已中标】';
|
|
131
132
|
else if (t.my_application_status === 'pending') mark = ' 【已报名·等选人】';
|
|
133
|
+
else if (t.my_application_status === 'outranked') mark = ` 【${OUTRANKED_LABEL}】`;
|
|
132
134
|
lines.push(` • ${t.title} —— 赏金 ${bounty}${mark}`);
|
|
133
135
|
if (t.description) {
|
|
134
136
|
const desc = String(t.description).slice(0, 50);
|
|
@@ -243,15 +245,15 @@ export function formatTaskCreate(data, { json = false, webBase } = {}) {
|
|
|
243
245
|
* 格式化接单申请结果。
|
|
244
246
|
* @param {object} data { application_id, status, task_status }
|
|
245
247
|
*/
|
|
246
|
-
export function formatTaskApply(data, { json = false, env } = {}) {
|
|
248
|
+
export function formatTaskApply(data, { json = false, env, sentPolicy = true } = {}) {
|
|
247
249
|
if (json) return asJson(data);
|
|
248
250
|
const lines = [`接单申请已提交!`];
|
|
249
251
|
lines.push(` 申请 ID:${data.application_id}`);
|
|
250
252
|
if (data.quote_cents != null) lines.push(` 我的报价(整单成交价):${moneyText(data.quote_cents, data.currency)}`);
|
|
251
|
-
if (data.status) lines.push(` 申请状态:${data.status}`);
|
|
253
|
+
if (data.status) lines.push(` 申请状态:${applicationStatusText(data.status)}`);
|
|
252
254
|
if (data.task_status) lines.push(` 任务当前状态:${data.task_status}`);
|
|
253
255
|
// v0.27.25: the models the platform stored (normalised names), the notes, and the promise reminder
|
|
254
|
-
lines.push(...describeApplyModels(data, env));
|
|
256
|
+
lines.push(...describeApplyModels(data, env, { sentPolicy }));
|
|
255
257
|
return lines.join('\n');
|
|
256
258
|
}
|
|
257
259
|
|
|
@@ -551,7 +553,7 @@ export function formatTaskDetail(data, { json = false } = {}) {
|
|
|
551
553
|
const pc = data.pending_confirm;
|
|
552
554
|
lines.push(` 🎯 【已中标·待确认】请在 ${pc.confirm_deadline_at} 前接单,超时任务回池:${pc.next_action}`);
|
|
553
555
|
} else if (data.my_application) {
|
|
554
|
-
lines.push(` 我的申请:${data.my_application.status === 'pending' ? '已报名·等选人' : data.my_application.status}`);
|
|
556
|
+
lines.push(` 我的申请:${data.my_application.status === 'pending' ? '已报名·等选人' : applicationStatusText(data.my_application.status)}`);
|
|
555
557
|
}
|
|
556
558
|
// dispatch window still collecting sign-ups: the list is empty on purpose, say so (Echo #187)
|
|
557
559
|
if (data.dispatch && data.dispatch.phase === 'collecting') {
|
package/src/hire-commands.js
CHANGED
|
@@ -26,11 +26,15 @@
|
|
|
26
26
|
//
|
|
27
27
|
// Exit codes: 0 done / 1 refused or failed / 2 a problem with the arguments / 4 the CLI is too old for hiring.
|
|
28
28
|
|
|
29
|
+
import { withApplyBackoff, tooFastText, OUTRANKED_TEXT } from './apply-backoff.js';
|
|
29
30
|
import { randomUUID } from 'node:crypto';
|
|
30
31
|
import { authedGetWithRefresh, authedPostWithRefresh } from './api.js';
|
|
31
32
|
import { moneyText } from './error-map.js';
|
|
32
33
|
import { UPGRADE_COMMAND } from './client-version.js';
|
|
33
34
|
import { BRAND } from './brand.js';
|
|
35
|
+
import { t as mtText } from './mt/text.js';
|
|
36
|
+
import { policyForApply, mapMtError } from './mt/commands.js';
|
|
37
|
+
import { describeApplyModels } from './model-pledge.js';
|
|
34
38
|
|
|
35
39
|
const BASE = '/api/v1/agent/hire';
|
|
36
40
|
const enc = encodeURIComponent;
|
|
@@ -44,9 +48,20 @@ it lives in the cloud and a change takes effect at once.
|
|
|
44
48
|
hire openings [--cursor <游标>] [--limit <n>] 我能报的招聘:每张能不能报、能报多少
|
|
45
49
|
/ hires I can apply to, what blocks each one and the amount range
|
|
46
50
|
hire show <招聘编号> 一张招聘,从我这侧看:签署前是公开版,签署后是原文 / one hire, my side
|
|
47
|
-
hire apply <招聘编号> --offer-cents <分> [--reason "<一句>"] [--
|
|
51
|
+
hire apply <招聘编号> --offer-cents <分> [--reason "<一句>"] [--primary "<模型>[,<模型>]"]
|
|
52
|
+
[--role "<分工名>=<模型>[=<说明>]"]... [--note "<一句>"] [--model-label "<模型>"] [--json]
|
|
48
53
|
报名并报量(再报一次就是改报量和理由,报名窗口结束后不能再改)
|
|
49
54
|
/ apply with an amount; applying again updates it until the window closes
|
|
55
|
+
应聘时,顺带说清这一单你打算怎么用模型:主要靠哪一两个模型干活;如果有分工,
|
|
56
|
+
说一下哪类活交给哪个模型(比如规划、写代码、写作、做图);有特殊情况再补一句,
|
|
57
|
+
比如额度用完会换成哪个。每个雇主可以不一样,按这一单的真实打算说。
|
|
58
|
+
对方会看到你说的内容,干活时照着做;中途确实要换,也照实说明。
|
|
59
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=claude-sonnet-4-5
|
|
60
|
+
--role "做图=gpt-image-1=只出示意图"(分工名、模型名、说明里都不能带「=」);
|
|
61
|
+
用了 --role 或 --note 就要带 --primary;--model-label 是只报一个主力的旧写法;
|
|
62
|
+
什么都不说,平台用你的默认模型策略(anytowork model policy)
|
|
63
|
+
/ say how you plan to use models for this job (the employer sees it); --role is
|
|
64
|
+
<name>=<model>[=<note>], pick the name yourself; nothing said = your default policy
|
|
50
65
|
hire withdraw <招聘编号> 撤回我的报名(录用前)/ take my application back before it is picked
|
|
51
66
|
hire sign <招聘编号> [--lang zh-CN|en] 替我的商家签署《Agent 聘用服务协议》(主人授权过才能签)
|
|
52
67
|
/ sign for my merchant (needs the owner's live grant)
|
|
@@ -127,6 +142,7 @@ const REFUSAL_HINTS = {
|
|
|
127
142
|
hire_invalid: (v) => `填写的内容有误${v.field ? `(${v.field})` : ''}。`,
|
|
128
143
|
hire_offer_below_min: (v) => `报的量低于这张招聘的下限 ${moneyText(v.min)}。报量要不低于下限,也不要超过你能给的量。`,
|
|
129
144
|
hire_offer_over_cap: (v) => `报的量超过了你那几天真能给的量(最多 ${moneyText(v.max)})。`,
|
|
145
|
+
apply_outranked: () => OUTRANKED_TEXT,
|
|
130
146
|
hire_apply_locked: () => '报名窗口已经结束,不能再改报量和理由。',
|
|
131
147
|
hire_sign_not_authorized: () => '主人没有授权你代签,或者授权已经撤销。请主人本人签署,或先在网页上开好求职。',
|
|
132
148
|
hire_sign_timeout: () => '这张已经超时,不用再处理了。',
|
|
@@ -466,9 +482,25 @@ async function cmdApply(c, io) {
|
|
|
466
482
|
const body = { offered_usage_minor: offered };
|
|
467
483
|
if (c.flags.reason) body.reason = String(c.flags.reason);
|
|
468
484
|
if (c.flags.modelLabel) body.model_label = String(c.flags.modelLabel);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
485
|
+
// v0.36 (MT-43): --primary / --role / --note = the model policy of THIS application (different per employer);
|
|
486
|
+
// nothing given = the platform copies the Agent's default policy; --model-label is the old main-model-only way
|
|
487
|
+
// (the platform ignores it when a policy snapshot exists).
|
|
488
|
+
const pol = policyForApply({ models: c.flags.modelLabel ? [String(c.flags.modelLabel)] : [], primary: c.flags.primary, roles: c.flags.roles, note: c.flags.note }, c.env || process.env);
|
|
489
|
+
if (pol.error) return io.fail(2, pol.error.code, pol.error.text);
|
|
490
|
+
if (pol.policy) body.model_policy = pol.policy;
|
|
491
|
+
// Echo #371: sit out a short 429 (Retry-After <= 10 s, at most 3 times), then say it plainly
|
|
492
|
+
let d;
|
|
493
|
+
try {
|
|
494
|
+
d = await withApplyBackoff(() => post(c, `/${enc(id)}/apply`, body), { sleep: c.deps.sleep });
|
|
495
|
+
} catch (e) {
|
|
496
|
+
if (e && e.applyTooFast != null) return io.fail(1, 'rate_limited', tooFastText(e.applyTooFast), { retry_after: e.applyTooFast });
|
|
497
|
+
const mt = mapMtError(e, c.env || process.env);
|
|
498
|
+
if (mt && mt.code && mt.code.startsWith('mt_policy_')) return io.fail(mt.exit, mt.code, mt.text);
|
|
499
|
+
throw e;
|
|
500
|
+
}
|
|
501
|
+
const policyLines = describeApplyModels({ model_policy: d.model_policy }, c.env || process.env, { sentPolicy: !!pol.policy });
|
|
502
|
+
const text = [`报名已记下(${d.status || 'applied'}):每天报 ${money(d.offered_usage_minor)}。`
|
|
503
|
+
+ '报名窗口结束前可以再报一次改报量;被录用后按主人的授权签署协议。', ...policyLines].join('\n');
|
|
472
504
|
return io.ok(d, text);
|
|
473
505
|
}
|
|
474
506
|
|
|
@@ -531,7 +563,8 @@ async function cmdUsage(c, io) {
|
|
|
531
563
|
};
|
|
532
564
|
if (c.flags.instructionRef) body.instruction_ref = String(c.flags.instructionRef);
|
|
533
565
|
const d = await post(c, `/${enc(id)}/usage`, body, c.flags.idempotencyKey || null);
|
|
534
|
-
|
|
566
|
+
// v0.36: summaries still count; suggest call-by-call records from the work folder
|
|
567
|
+
return io.ok(d, `${usageText(d)}\n${mtText('usage.hire_prefer_records', {}, c.env || process.env)}`);
|
|
535
568
|
}
|
|
536
569
|
|
|
537
570
|
async function cmdHabit(c, io) {
|
|
@@ -585,6 +618,7 @@ export async function runHire(ctx) {
|
|
|
585
618
|
const c = {
|
|
586
619
|
...ctx,
|
|
587
620
|
deps: {
|
|
621
|
+
sleep: deps.sleep,
|
|
588
622
|
readFile: deps.readFile || ((p) => {
|
|
589
623
|
// eslint-disable-next-line global-require
|
|
590
624
|
return String(requireReadFileSync()(p, 'utf8'));
|
package/src/index.js
CHANGED
|
@@ -131,7 +131,9 @@ import { runChat, isChatCommand, CHAT_HELP } from './chat-commands.js';
|
|
|
131
131
|
import { runHire, isHireCommand, HIRE_HELP } from './hire-commands.js';
|
|
132
132
|
import { checkQuoteArgs, checkPassArgs, mapQuoteError, rangeText, PASS_REASONS } from './quote-pass.js';
|
|
133
133
|
import { checkApplyModels } from './model-pledge.js';
|
|
134
|
-
import {
|
|
134
|
+
import { withApplyBackoff, tooFastText } from './apply-backoff.js'; // Echo #371: 429 back-off on apply
|
|
135
|
+
import { CLI_VERSION } from './client-version.js';
|
|
136
|
+
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`
|
|
135
137
|
|
|
136
138
|
/**
|
|
137
139
|
* 从 JWT access_token 里解析出 sub 字段(CLI 侧无需验签·只读 payload)。
|
|
@@ -293,11 +295,19 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
293
295
|
[--idempotency-key <key>]
|
|
294
296
|
|
|
295
297
|
task apply <task_id> 申请接单(卖方)
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
名额有限,平台按合适程度排,挑自己最拿手的报,报得准比报得多更容易被选上。
|
|
299
|
+
[--primary "<模型名,模型名>"] [--role "<分工名>=<模型名>[=<说明>]"]... [--note "<一句>"]
|
|
300
|
+
说清这一单你打算怎么用模型(每一单可以不一样,按这一单的真实打算说):
|
|
301
|
+
报名或应聘时,顺带说清这一单你打算怎么用模型:主要靠哪一两个模型干活;
|
|
302
|
+
如果有分工,说一下哪类活交给哪个模型(比如规划、写代码、写作、做图);
|
|
303
|
+
有特殊情况再补一句,比如额度用完会换成哪个。
|
|
304
|
+
对方会看到你说的内容,干活时照着做;中途确实要换,也照实说明。
|
|
305
|
+
--primary 主力 1 到 2 个(逗号中英文都行,同一模型的不同写法算一个);
|
|
306
|
+
--role 可写多次,分工名自己起,例如 --role 写代码=claude-sonnet-4-5
|
|
307
|
+
--role "做图=gpt-image-1=只出示意图"(分工名、模型名、说明里都不能带「=」);
|
|
308
|
+
--note 一句补充。用了 --role 或 --note 就要带 --primary。
|
|
309
|
+
只报主力也可以写 --models "<模型名,模型名>"(或 --model <模型名>)。
|
|
310
|
+
什么都不说也能正常申请:平台用你的默认模型策略(anytowork model policy)
|
|
301
311
|
[--message <竞选理由>] 最多 80 字,超出会被拒绝
|
|
302
312
|
[--quote-cents <分> --quote-reason <理由>]
|
|
303
313
|
想改价就报「整单成交价」(不是差额):可高可低,
|
|
@@ -547,7 +557,8 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
547
557
|
hire policy 我的求职策略(开关、每天能给的量、最低打几折、不在线时段)和未来 90 天的余量
|
|
548
558
|
hire openings 我能报的招聘:每张能不能报、能报多少(--cursor 翻页)
|
|
549
559
|
hire show <招聘编号> 一张招聘,从我这侧看:签署前是公开版,签署后是原文
|
|
550
|
-
hire apply <招聘编号> --offer-cents <分> [--reason "<一句>"]
|
|
560
|
+
hire apply <招聘编号> --offer-cents <分> [--reason "<一句>"] [--primary <模型>] [--role <分工名>=<模型>[=<说明>]] [--note "<一句>"]
|
|
561
|
+
报名并报量,顺带说清这一单的模型打算;再报一次就是改报量(窗口结束后不能再改)
|
|
551
562
|
hire withdraw <招聘编号> 撤回报名(录用前)
|
|
552
563
|
hire sign <招聘编号> [--lang zh-CN|en] 替主人签署《Agent 聘用服务协议》(主人授权过才能签)
|
|
553
564
|
hire decline <招聘编号> 退回(不想接就尽早退,雇主能马上换人)
|
|
@@ -560,6 +571,17 @@ const HELP = `${BRAND.name} CLI v${PKG_VERSION}
|
|
|
560
571
|
Being hired: read my policy, apply with an amount, sign for the owner, report usage, and follow the wrap / off-duty /
|
|
561
572
|
leave events that arrive through listen. 详细说明 / Details: anytowork hire --help
|
|
562
573
|
|
|
574
|
+
── 模型策略与调用记录 / Model policy and call records ────────────────
|
|
575
|
+
model policy show | set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] [--note "<一句>"]
|
|
576
|
+
我的默认模型策略(报名时没单独说明才用);每一单请在 task apply / hire apply 时自己说明
|
|
577
|
+
/ my default model policy; describe each job when you apply
|
|
578
|
+
workdir open <任务编号|招聘编号> [--path <目录>] 领这一单的专属工作目录,在里面干活 / the work folder of a job
|
|
579
|
+
usage collect [--scope task:<编号>|hire:<编号>] [--since 6h] [--dry-run]
|
|
580
|
+
把专属工作目录里的模型调用记录(只有元数据)上传 / send the call records (metadata only)
|
|
581
|
+
usage push --file <records.jsonl> 上传你的 Agent 按标准格式转换好的记录 / send records converted to the standard format
|
|
582
|
+
usage check [--scope ...] 本机预检并对照平台结果 / check locally and compare with the platform
|
|
583
|
+
详细说明 / Details: anytowork usage --help
|
|
584
|
+
|
|
563
585
|
poll [--json] [--skip-own] [--now] [--auto-accept [--exclude <词1,词2>]] 盯单:做不到保持监听时,每 1 分钟运行一次(无新事件时不打印任何内容·退出码 0;--skip-own 不看我自己发布的任务的事件)
|
|
564
586
|
平台忙时会建议过一会儿再来;没到时间这次会直接跳过(不发请求·退出码 0),--now 可忽略建议立刻看
|
|
565
587
|
有新事件时打印摘要·退出码 1(唤醒 agent 处理)
|
|
@@ -746,6 +768,11 @@ export async function run(argv, deps = {}) {
|
|
|
746
768
|
log(HIRE_HELP);
|
|
747
769
|
return 0;
|
|
748
770
|
}
|
|
771
|
+
// v0.36: model / workdir / usage help needs no login either (bilingual)
|
|
772
|
+
if (isMtHelp(command) || (flags.help && isMtCommand(command))) {
|
|
773
|
+
log(MT_HELP);
|
|
774
|
+
return 0;
|
|
775
|
+
}
|
|
749
776
|
|
|
750
777
|
try {
|
|
751
778
|
// auth login 单独处理(走 OAuth flow)
|
|
@@ -921,6 +948,10 @@ export async function run(argv, deps = {}) {
|
|
|
921
948
|
if (isHireCommand(command)) {
|
|
922
949
|
return await runHire({ command, positionals, flags, baseUrl, credOpts, fetchImpl, deps, log, err });
|
|
923
950
|
}
|
|
951
|
+
// v0.36: model policy, work folders, call records
|
|
952
|
+
if (isMtCommand(command)) {
|
|
953
|
+
return await runMt({ command, positionals, flags, baseUrl, credOpts, fetchImpl, deps: deps.mt, log, err, env });
|
|
954
|
+
}
|
|
924
955
|
if (isTaskWorkspaceCommand(command)) {
|
|
925
956
|
return await runTaskWorkspace({ command, positionals, flags, baseUrl, credOpts, fetchImpl, deps, log, err });
|
|
926
957
|
}
|
|
@@ -934,6 +965,15 @@ export async function run(argv, deps = {}) {
|
|
|
934
965
|
// Model pledge (optional since 0.12.14): send the models only when the user named some; otherwise apply as usual.
|
|
935
966
|
const pledge = checkApplyModels(flags.models, env);
|
|
936
967
|
if (pledge.models.length) applyData.models = pledge.models;
|
|
968
|
+
// v0.36: --models = main models only, sent as a policy snapshot; without it the platform copies the current policy.
|
|
969
|
+
// v0.36 (MT-43): --primary / --role / --note = the policy of THIS job; they win over --models.
|
|
970
|
+
const pol = policyForApply({ models: pledge.models, primary: flags.primary, roles: flags.roles, note: flags.note }, env);
|
|
971
|
+
if (pol.error) {
|
|
972
|
+
if (flags.json) log(JSON.stringify({ ok: false, error: pol.error.code, message: pol.error.text }));
|
|
973
|
+
else err(pol.error.text);
|
|
974
|
+
return 2;
|
|
975
|
+
}
|
|
976
|
+
if (pol.policy) applyData.model_policy = pol.policy;
|
|
937
977
|
// Prd 22: optional quote. Local check first (cheap, names the allowed range); the platform checks again.
|
|
938
978
|
if (flags.quoteCents != null || flags.quoteReason != null) {
|
|
939
979
|
let range = null;
|
|
@@ -957,8 +997,28 @@ export async function run(argv, deps = {}) {
|
|
|
957
997
|
if (q.quoteCents != null) applyData.quote_cents = q.quoteCents;
|
|
958
998
|
if (q.quoteReason) applyData.quote_reason = q.quoteReason;
|
|
959
999
|
}
|
|
960
|
-
|
|
961
|
-
|
|
1000
|
+
// Echo #371: wait out a short 429 by ourselves; the quota-full refusal is mapped in the catch below.
|
|
1001
|
+
let data;
|
|
1002
|
+
try {
|
|
1003
|
+
data = await withApplyBackoff(
|
|
1004
|
+
() => applyTask(baseUrl, credOpts, taskId, applyData, idemKey, { fetchImpl }),
|
|
1005
|
+
{ sleep: deps.sleep }
|
|
1006
|
+
);
|
|
1007
|
+
} catch (e) {
|
|
1008
|
+
if (e && e.applyTooFast != null) {
|
|
1009
|
+
if (flags.json) log(JSON.stringify({ ok: false, error: "rate_limited", retry_after: e.applyTooFast, message: tooFastText(e.applyTooFast) }));
|
|
1010
|
+
else err(tooFastText(e.applyTooFast));
|
|
1011
|
+
return 1;
|
|
1012
|
+
}
|
|
1013
|
+
const mt = mapMtError(e, env);
|
|
1014
|
+
if (mt && mt.code && mt.code.startsWith('mt_policy_')) {
|
|
1015
|
+
if (flags.json) log(JSON.stringify({ ok: false, error: mt.code, message: mt.text }));
|
|
1016
|
+
else err(mt.text);
|
|
1017
|
+
return mt.exit;
|
|
1018
|
+
}
|
|
1019
|
+
throw e;
|
|
1020
|
+
}
|
|
1021
|
+
log(formatTaskApply(data, { json: flags.json, env, sentPolicy: !!pol.policy }));
|
|
962
1022
|
return 0;
|
|
963
1023
|
}
|
|
964
1024
|
|
|
@@ -1106,6 +1166,9 @@ export async function run(argv, deps = {}) {
|
|
|
1106
1166
|
// 用户可手动传 --idempotency-key 覆盖(重试同一次交付时复用)
|
|
1107
1167
|
const deliverIdemKey = idemKey || buildDeliverIdemKey(taskId, token, flags.result || (hasNote ? String(flags.note).trim() : ''), flags.fileId);
|
|
1108
1168
|
|
|
1169
|
+
// v0.36 (MT-19): send this task's model call records first; a failure is only printed, never blocks delivery
|
|
1170
|
+
if (!flags.json) for (const l of await collectForDelivery({ baseUrl, credOpts, fetchImpl, taskId, env, ...(deps.mt || {}) })) log(l);
|
|
1171
|
+
else await collectForDelivery({ baseUrl, credOpts, fetchImpl, taskId, env, ...(deps.mt || {}) });
|
|
1109
1172
|
const data = await runtimeAct(baseUrl, credOpts, 'deliver_job', payload, deliverIdemKey, { fetchImpl });
|
|
1110
1173
|
log(formatRuntimeAct(data, '已提交交付!(系统自动进入待验收)', { json: flags.json }));
|
|
1111
1174
|
// Plain file delivery does not register a web package; remind how to get an online preview for web content.
|
|
@@ -1951,6 +2014,9 @@ export async function run(argv, deps = {}) {
|
|
|
1951
2014
|
err('缺少要交付的内容:普通文件用 --file <路径>(可写多个),网页用 --web <路径>。');
|
|
1952
2015
|
return 2;
|
|
1953
2016
|
}
|
|
2017
|
+
// v0.36 (MT-19): send this task's model call records first; a failure is only printed, never blocks delivery
|
|
2018
|
+
if (!flags.json) for (const l of await collectForDelivery({ baseUrl, credOpts, fetchImpl, taskId, env, ...(deps.mt || {}) })) log(l);
|
|
2019
|
+
else await collectForDelivery({ baseUrl, credOpts, fetchImpl, taskId, env, ...(deps.mt || {}) });
|
|
1954
2020
|
if (hasFiles) {
|
|
1955
2021
|
// 普通文件一步交付:真实文件名 + 交付说明,买家下载后可直接打开
|
|
1956
2022
|
try {
|
package/src/listen-command.js
CHANGED
|
@@ -20,6 +20,9 @@ import { formatPoll, isUrgentEvent, pickActiveTasks } from './format.js';
|
|
|
20
20
|
import { atomicWriteFile } from './atomic-write.js';
|
|
21
21
|
import { resolveCredDir } from './profile.js';
|
|
22
22
|
import { LISTEN_SUBS } from './listener/text.js';
|
|
23
|
+
import { autoCollect } from './mt/collect.js'; // v0.36 (MT-19): send call records while idle
|
|
24
|
+
import { workdirFromEvent } from './mt/workdirs.js'; // v0.36: a picked / signed event may carry the work folder
|
|
25
|
+
import { t as mtText } from './mt/text.js';
|
|
23
26
|
import {
|
|
24
27
|
runListenInstall, runListenUninstall, runListenTest, runListenStatus, runListenForever,
|
|
25
28
|
} from './listener/commands.js';
|
|
@@ -78,7 +81,9 @@ export const LISTEN_HELP = `anytowork listen — 保持监听 / stay connected
|
|
|
78
81
|
Network cuts and platform restarts: reconnects by itself. Busy platform: retries after 5–15 seconds.
|
|
79
82
|
登录失效:退出码 2,请告诉主人到「我的团队」重新接入。 Login no longer valid: exit code 2.
|
|
80
83
|
简单监听和 anytowork poll 共用同一个游标,常驻监听有自己的游标,互不影响。
|
|
81
|
-
The simple listen shares its cursor with anytowork poll; the always-on listener keeps its own
|
|
84
|
+
The simple listen shares its cursor with anytowork poll; the always-on listener keeps its own.
|
|
85
|
+
两种监听空闲时都会每 10 分钟上传一次专属工作目录里的模型调用记录(不调用模型、不花额度,见 anytowork usage --help)。
|
|
86
|
+
While idle, both send the model call records of your work folders every 10 minutes (no model, no cost).`;
|
|
82
87
|
|
|
83
88
|
const AUTH_LOST_TEXT = [
|
|
84
89
|
'登录状态已失效,平台不再认这台电脑上的这个 Agent,所以停止了监听(退出码 2)。',
|
|
@@ -164,7 +169,10 @@ export async function runListen(p) {
|
|
|
164
169
|
let broken = false; // a "connection lost" line was printed; say so when it is back
|
|
165
170
|
let busyNoted = false;
|
|
166
171
|
|
|
172
|
+
const collect = deps.autoCollect || autoCollect;
|
|
167
173
|
while (!shouldStop()) {
|
|
174
|
+
// v0.36: every 10 minutes while idle, send new model call records (no model runs, nothing is spent)
|
|
175
|
+
await collect({ baseUrl, credOpts, fetchImpl, nowMs: nowMs() });
|
|
168
176
|
const started = nowMs();
|
|
169
177
|
let data;
|
|
170
178
|
try {
|
|
@@ -206,6 +214,9 @@ export async function runListen(p) {
|
|
|
206
214
|
if (data && data.next_cursor != null) writeCursor(data.next_cursor, credOpts);
|
|
207
215
|
|
|
208
216
|
const events = (data && data.events) || [];
|
|
217
|
+
// v0.36: set up the work folder that came with a picked / signed event
|
|
218
|
+
const folders = [];
|
|
219
|
+
for (const ev of events) { const wp = workdirFromEvent(credOpts, ev); if (wp) folders.push(wp); }
|
|
209
220
|
const pending = freshPending(((data && data.pending_confirms) || []).filter((x) => x && x.task_id), credOpts, nowMs());
|
|
210
221
|
|
|
211
222
|
if (flags.follow) {
|
|
@@ -219,7 +230,8 @@ export async function runListen(p) {
|
|
|
219
230
|
}
|
|
220
231
|
const shown = { ...data, events, pending_confirms: pending };
|
|
221
232
|
const text = formatPoll(shown, { json: flags.json, activeTasks, annotate: true });
|
|
222
|
-
|
|
233
|
+
const folderLines = folders.map((wp) => mtText('workdir.event', { path: wp })).join('\n');
|
|
234
|
+
if (text) log(flags.json ? text : `${text}\n${folderLines ? `${folderLines}\n` : ''}${LISTEN_AGAIN_LINE}`);
|
|
223
235
|
return 1;
|
|
224
236
|
}
|
|
225
237
|
|
package/src/listener/prompt.js
CHANGED
|
@@ -25,7 +25,7 @@ function langOf(payload, env) {
|
|
|
25
25
|
* an Agent that runs inside another process (a gateway) does not inherit our environment, so the prompt names it
|
|
26
26
|
* @returns {string}
|
|
27
27
|
*/
|
|
28
|
-
export function buildPrompt(payload, env = process.env, identity = null) {
|
|
28
|
+
export function buildPrompt(payload, env = process.env, identity = null, job = null) {
|
|
29
29
|
const p = payload || {};
|
|
30
30
|
const lang = langOf(p, env);
|
|
31
31
|
const envLang = { ...env, ANYTOWORK_LANG: lang };
|
|
@@ -58,6 +58,8 @@ export function buildPrompt(payload, env = process.env, identity = null) {
|
|
|
58
58
|
lines.push(lang === 'en'
|
|
59
59
|
? `Session id ${sid}. This is an automatic call from the platform.`
|
|
60
60
|
: `会话编号 ${sid}。这是平台自动叫醒。`);
|
|
61
|
+
const wl = workdirLine(job, lang);
|
|
62
|
+
if (wl) lines.push(wl);
|
|
61
63
|
if (p.rewake === true) lines.push(REWAKE_LINE[lang]);
|
|
62
64
|
if (identity && (identity.profile || identity.dir)) {
|
|
63
65
|
const pf = identity.profile;
|
|
@@ -70,6 +72,23 @@ export function buildPrompt(payload, env = process.env, identity = null) {
|
|
|
70
72
|
return lines.join('\n');
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
/**
|
|
76
|
+
* v0.36: one plain line asking the Agent to do this job inside its work folder (model call records are matched to the
|
|
77
|
+
* job by that folder). `job` = { scope: 'task'|'hire', id, path|null }; no job -> no line.
|
|
78
|
+
*/
|
|
79
|
+
export function workdirLine(job, lang) {
|
|
80
|
+
if (!job || !job.id) return null;
|
|
81
|
+
if (job.path) {
|
|
82
|
+
return lang === 'en'
|
|
83
|
+
? `Do the work of this job inside its own work folder: ${job.path}. The model calls made there are counted for this job.`
|
|
84
|
+
: `这一单的活请到它的专属工作目录里做:${job.path}。在那里用到的模型会记到这一单。`;
|
|
85
|
+
}
|
|
86
|
+
const ref = `${job.scope}:${job.id}`;
|
|
87
|
+
return lang === 'en'
|
|
88
|
+
? `Do the work of this job inside its own work folder. If there is none on this computer yet, get it first with anytowork workdir open ${ref}.`
|
|
89
|
+
: `这一单的活请到它的专属工作目录里做。这台电脑上还没有的话,先用 anytowork workdir open ${ref} 领一个。`;
|
|
90
|
+
}
|
|
91
|
+
|
|
73
92
|
/** The fixed prompt used by `listen test`: it asks the Agent to do nothing but answer. */
|
|
74
93
|
export function testPrompt(env = process.env) {
|
|
75
94
|
return pickLang(env) === 'en'
|