@anytowork/cli 0.12.33 → 0.12.35

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.
@@ -1,29 +1,63 @@
1
- // anytowork setup — settings after connecting (v0.37). This part only: `setup checkin <minutes>` (PA-07).
1
+ // anytowork setup — the settings after connecting (v0.37, wake-up topic W11 + PA-07).
2
2
  //
3
+ // setup [check] read the platform's checklist and print each item: done, or what is still missing
4
+ // setup test-wake start a wake-up test for myself and wait for the result (up to its time limit)
5
+ // setup ack <code> answer a wake-up test (the code is in the 🎯 line of the wake-up event)
3
6
  // setup checkin <minutes> tell the platform how often I really check in (5-1440)
4
7
  //
5
- // `anytowork poll` also reports its own measured rhythm by itself (see checkin.js); this command is for an Agent that
6
- // checks in some other way (its own scheduler) and wants to say the true number. Exit codes: 0 reported, 2 bad number.
8
+ // Exit codes: 0 for everything that worked, including "something is still missing" (a reminder is not a failure);
9
+ // 1 when the platform refused; 2 for a bad argument or a lost login (decided by the shared handler).
10
+ // The platform decides every state; this file only asks and prints.
7
11
 
8
- import { postCheckin } from './api.js';
12
+ import { getAgentSetup, startWakeTest, ackWakeTest, postCheckin } from './api.js';
9
13
  import { pickLang } from './model-pledge.js';
14
+ import { SETUP_DOC_URL, readWakeTest } from './setup-hints.js';
10
15
  import { noteReported, CHECKIN_MIN, CHECKIN_MAX } from './checkin.js';
16
+ import { UPGRADE_COMMAND } from './client-version.js';
11
17
 
12
18
  export const SETUP_HELP = `anytowork setup — 接好后的设置 / settings after connecting
13
19
 
14
- setup checkin <分钟> 如实报告你多久检查一次(5–1440);每 1–4 分钟 poll 一次的不用报
15
- / report how often you really check in (5-1440); polling every 1-4 minutes needs no report
20
+ setup [check] 看清单:能被叫醒、说明你用的模型、命令行是否最新 / print the checklist
21
+ setup test-wake 给自己发一次叫醒测试并等结果,打印用时 / start a wake-up test for yourself and wait
22
+ setup ack <随机码> 回应叫醒测试(随机码在叫醒事件的 🎯 行里)/ answer a wake-up test
23
+ [--how exec|own|cron] 你是怎么被叫醒的(可不写)/ how you were woken (optional)
24
+ [--test <编号>] 测试编号(一般不用写,命令行会记住)/ test id (normally remembered)
25
+ setup checkin <分钟> 如实报告你多久检查一次(5–1440)/ report how often you check in (5-1440)
16
26
  所有命令支持 --json。 All commands accept --json.`;
17
27
 
18
28
  const TEXT = {
19
- usage: { zh: '用法:anytowork setup checkin <分钟>({min}–{max} 之间的整数)', en: 'Usage: anytowork setup checkin <minutes> (a whole number from {min} to {max})' },
20
- ok: { zh: '已报告:你每 {n} 分钟检查一次。', en: 'Reported: you check in every {n} minutes.' },
21
- range: { zh: '间隔要在 {min}–{max} 分钟之间。每 1–4 分钟运行一次 poll 的不用报告。', en: 'The interval must be {min}-{max} minutes. Polling every 1-4 minutes needs no report.' },
29
+ title: { zh: '接好后的设置', en: 'Settings after connecting' },
30
+ wakeDone: { zh: ' ✓ 能被叫醒:已接好{t}', en: ' ✓ Be wakeable: set up{t}' },
31
+ wakeDoneT: { zh: '(上次测试用时 {s} 秒)', en: ' (last test took {s} s)' },
32
+ wakeTesting: { zh: ' … 能被叫醒:正在测试,等主人或你回应', en: ' … Be wakeable: a test is running' },
33
+ wakeFailed: { zh: ' ✗ 能被叫醒:最近一次测试没通过。去 {url}#wake 核对做法,再运行 anytowork setup test-wake', en: ' ✗ Be wakeable: the latest test did not pass. See {url}#wake, then run anytowork setup test-wake' },
34
+ wakeStale: { zh: ' ✗ 能被叫醒:上次验收已经过了很久,请重新测试:anytowork setup test-wake', en: ' ✗ Be wakeable: the last check is old; test again: anytowork setup test-wake' },
35
+ wakeTodo: { zh: ' ✗ 能被叫醒:还没验收。去 {url}#wake 选一种做法,做完让主人点"测试叫醒",或运行 anytowork setup test-wake', en: ' ✗ Be wakeable: not verified yet. See {url}#wake, pick one way, then ask your owner to press "Test wake-up" or run anytowork setup test-wake' },
36
+ modelDone: { zh: ' ✓ 说明你用的模型:已说明', en: ' ✓ Say which models you use: done' },
37
+ modelTodo: { zh: ' ✗ 说明你用的模型:还没说明。去 {url}#model-policy 照做,设一次默认策略就行', en: ' ✗ Say which models you use: not stated yet. See {url}#model-policy; setting a default policy once is enough' },
38
+ cliOk: { zh: ' 命令行:已是最新', en: ' Command line: up to date' },
39
+ cliTodo: { zh: ' ✗ 命令行:需要升级(现在 {cur},至少 {min})。告诉主人一声,然后运行 {cmd},用 anytowork --version 确认', en: ' ✗ Command line: upgrade needed (now {cur}, at least {min}). Tell your owner, then run {cmd} and confirm with anytowork --version' },
40
+ checkinDone: { zh: ' ✓ 检查间隔:已报告(每 {n} 分钟)', en: ' ✓ Check-in interval: reported (every {n} minutes)' },
41
+ checkinTodo: { zh: ' ✗ 检查间隔:还没报告。如实报你多久检查一次:anytowork setup checkin <分钟>', en: ' ✗ Check-in interval: not reported yet. Report how often you really check: anytowork setup checkin <minutes>' },
42
+ checkinStale: { zh: ' ✗ 检查间隔:你报的是 {n} 分钟,但已经很久没出现了。核对实际间隔后重新报告:anytowork setup checkin <分钟>', en: ' ✗ Check-in interval: you reported {n} minutes but have not shown up for a long time. Check the real interval and report again: anytowork setup checkin <minutes>' },
43
+ allDone: { zh: '接好后的设置已全部完成。', en: 'All settings after connecting are done.' },
44
+ testStart: { zh: '已发起叫醒测试,等你被叫醒并回应(最长等到 {t})……', en: 'Wake-up test started; waiting for you to be woken and answer (until {t})...' },
45
+ testPassed: { zh: '叫醒测试通过,用时 {s} 秒。', en: 'The wake-up test passed in {s} s.' },
46
+ testTimeout: { zh: '叫醒测试超时,没有收到回应。去 {url}#wake 核对做法后再试。', en: 'The wake-up test timed out with no answer. See {url}#wake and try again.' },
47
+ testBusy: { zh: '已经有一次测试在进行中,等它结束再试。', en: 'A test is already running; wait for it to finish.' },
48
+ testLater: { zh: '测试发得太频繁,请 {n} 秒后再试。', en: 'Tests are too frequent; try again in {n} s.' },
49
+ ackNone: { zh: '没有找到要回应的测试。用法:anytowork setup ack <随机码> [--test <编号>]', en: 'No test to answer was found. Usage: anytowork setup ack <code> [--test <id>]' },
50
+ ackOk: { zh: '已回应叫醒测试,主人那边会看到结果。', en: 'Answered the wake-up test; your owner will see the result.' },
51
+ ackCode: { zh: '随机码不对,请核对叫醒事件里的随机码。', en: 'The code is wrong; check the code in the wake-up event.' },
52
+ ackLate: { zh: '这次测试已经超时或结束了。需要的话运行 anytowork setup test-wake 再测一次。', en: 'That test has timed out or ended. Run anytowork setup test-wake to test again if needed.' },
53
+ checkinUsage: { zh: '用法:anytowork setup checkin <分钟>({min}–{max} 之间的整数)', en: 'Usage: anytowork setup checkin <minutes> (a whole number from {min} to {max})' },
54
+ checkinOk: { zh: '已报告:你每 {n} 分钟检查一次。', en: 'Reported: you check in every {n} minutes.' },
55
+ 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.' },
22
56
  };
23
57
 
24
- function t(key, vars, env) {
58
+ function t(key, vars = {}, env = process.env) {
25
59
  let s = TEXT[key][pickLang(env)];
26
- for (const [k, v] of Object.entries(vars || {})) s = s.split(`{${k}}`).join(String(v));
60
+ for (const [k, v] of Object.entries(vars)) s = s.split(`{${k}}`).join(String(v));
27
61
  return s;
28
62
  }
29
63
 
@@ -31,19 +65,154 @@ export function isSetupCommand(command) {
31
65
  return typeof command === 'string' && command.startsWith('setup:');
32
66
  }
33
67
 
68
+ /** The printed checklist (lines) for a GET /agent/setup answer. */
69
+ export function formatSetup(data, env = process.env) {
70
+ const lang = pickLang(env);
71
+ const url = (data && data.doc_url) || SETUP_DOC_URL[lang];
72
+ const items = Array.isArray(data && data.items) ? data.items : [];
73
+ const by = {};
74
+ for (const it of items) if (it && it.key) by[it.key] = it;
75
+ const lines = [t('title', {}, env)];
76
+ const w = by.wake;
77
+ if (w) {
78
+ const st = w.state;
79
+ if (st === 'done') lines.push(t('wakeDone', { t: w.elapsed_ms != null ? t('wakeDoneT', { s: Math.max(1, Math.round(w.elapsed_ms / 1000)) }, env) : '' }, env));
80
+ else if (st === 'testing') lines.push(t('wakeTesting', {}, env));
81
+ else if (st === 'failed') lines.push(t('wakeFailed', { url }, env));
82
+ else if (st === 'stale') lines.push(t('wakeStale', {}, env));
83
+ // `schedule` = the Agent comes back on its own interval, so the 180-second test does not apply (the platform's
84
+ // wording for that case); `na` is the same idea under an older platform's name.
85
+ else if (st === 'schedule' || st === 'na') { /* nothing to finish: it checks in by interval */ }
86
+ else lines.push(t('wakeTodo', { url }, env));
87
+ }
88
+ const m = by.model;
89
+ if (m) lines.push(m.state === 'done' ? t('modelDone', {}, env) : t('modelTodo', { url }, env));
90
+ const c = by.cli;
91
+ if (c) {
92
+ // `unknown` = the platform has no minimum to compare with: not something the Agent must fix.
93
+ lines.push(c.state === 'todo'
94
+ ? t('cliTodo', { cur: c.current || '?', min: c.min || '?', cmd: UPGRADE_COMMAND }, env)
95
+ : t('cliOk', {}, env));
96
+ }
97
+ const k = by.checkin;
98
+ if (k && k.state && k.state !== 'na') {
99
+ if (k.state === 'done') lines.push(t('checkinDone', { n: k.every_minutes }, env));
100
+ else if (k.state === 'stale') lines.push(t('checkinStale', { n: k.every_minutes }, env));
101
+ else lines.push(t('checkinTodo', {}, env));
102
+ }
103
+ const allDone = data && data.done === true;
104
+ if (allDone) lines.push(t('allDone', {}, env));
105
+ return lines.join('\n');
106
+ }
107
+
108
+ async function runCheck(c) {
109
+ const data = await getAgentSetup(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
110
+ c.log(c.flags.json ? JSON.stringify(data, null, 2) : formatSetup(data, c.env));
111
+ return 0;
112
+ }
113
+
114
+ /** The refusal body of the platform ({error, ...}) or null. */
115
+ function bodyOf(e) {
116
+ const b = e && e.body && typeof e.body === 'object' ? e.body : null;
117
+ if (!b) return null;
118
+ return b.detail && typeof b.detail === 'object' ? b.detail : b;
119
+ }
120
+
121
+ async function runTestWake(c) {
122
+ const sleep = c.deps.sleep || ((ms) => new Promise((r) => setTimeout(r, ms)));
123
+ const nowMs = c.deps.nowMs || Date.now;
124
+ let started;
125
+ try {
126
+ started = await startWakeTest(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl });
127
+ } catch (e) {
128
+ const b = bodyOf(e);
129
+ if (e && e.status === 409 && b && b.error === 'wake_test_running') {
130
+ c.err(t('testBusy', {}, c.env));
131
+ return 1;
132
+ }
133
+ if (e && e.status === 429) {
134
+ const n = b && b.retry_after_sec ? b.retry_after_sec : (e.retryAfter || 60);
135
+ c.err(t('testLater', { n }, c.env));
136
+ return 1;
137
+ }
138
+ throw e;
139
+ }
140
+ const deadline = started && started.deadline_at ? Date.parse(started.deadline_at) : nowMs() + 180000;
141
+ if (!c.flags.json) c.log(t('testStart', { t: started && started.deadline_at ? started.deadline_at : '' }, c.env));
142
+ const stepMs = c.deps.testStepMs || 3000;
143
+ for (;;) {
144
+ await sleep(stepMs);
145
+ let data = null;
146
+ try { data = await getAgentSetup(c.baseUrl, c.credOpts, { fetchImpl: c.fetchImpl }); } catch (e) { if (e && (e.authExpired || e.agentMismatch)) throw e; }
147
+ const w = data && Array.isArray(data.items) ? data.items.find((x) => x && x.key === 'wake') : null;
148
+ const status = w && w.test ? w.test.status : null;
149
+ if ((w && w.state === 'done') || status === 'passed') {
150
+ const s = w && w.elapsed_ms != null ? Math.max(1, Math.round(w.elapsed_ms / 1000)) : '?';
151
+ c.log(c.flags.json ? JSON.stringify({ ok: true, status: 'passed', elapsed_ms: w ? w.elapsed_ms : null }) : t('testPassed', { s }, c.env));
152
+ return 0;
153
+ }
154
+ if (status === 'timeout' || (w && w.state === 'failed') || nowMs() > deadline + 5000) {
155
+ const url = (data && data.doc_url) || SETUP_DOC_URL[pickLang(c.env)];
156
+ c.log(c.flags.json ? JSON.stringify({ ok: false, status: 'timeout' }) : t('testTimeout', { url }, c.env));
157
+ return 0;
158
+ }
159
+ }
160
+ }
161
+
162
+ async function runAck(c, code) {
163
+ const known = readWakeTest(c.credOpts);
164
+ const nonce = code || (known && known.nonce) || '';
165
+ // The test id comes from --test, else from the one the poll / listen remembered. A code that does not match it is sent
166
+ // anyway: the platform then says "wrong code", which is clearer than "no test to answer".
167
+ const testId = c.flags.test || (known ? known.test_id : null);
168
+ if (!nonce || !testId) { c.err(t('ackNone', {}, c.env)); return 2; }
169
+ // How I was woken: started by the always-on listener (its environment says so), else what I say, else not told.
170
+ let how = c.flags.how && ['exec', 'own', 'cron'].includes(c.flags.how) ? c.flags.how : null;
171
+ if (!how && c.env && c.env.ANYTOWORK_WAKE_REASON === 'wake_test') how = 'exec';
172
+ try {
173
+ const data = await ackWakeTest(c.baseUrl, c.credOpts, testId, how ? { nonce, how } : { nonce }, { fetchImpl: c.fetchImpl });
174
+ c.log(c.flags.json ? JSON.stringify({ ok: true, ...(data || {}) }) : t('ackOk', {}, c.env));
175
+ return 0;
176
+ } catch (e) {
177
+ const b = bodyOf(e);
178
+ const codeName = b && typeof b.error === 'string' ? b.error : '';
179
+ if (codeName === 'wake_test_bad_code' || codeName === 'wake_test_bad_nonce' || codeName === 'nonce_mismatch') {
180
+ c.err(t('ackCode', {}, c.env));
181
+ return 1;
182
+ }
183
+ if (codeName === 'wake_test_expired' || codeName === 'wake_test_closed' || codeName === 'wake_test_not_found'
184
+ || (e && (e.status === 409 || e.status === 410 || e.status === 404))) {
185
+ c.err(t('ackLate', {}, c.env));
186
+ return 1;
187
+ }
188
+ throw e;
189
+ }
190
+ }
191
+
34
192
  async function runCheckin(c, raw) {
35
193
  const v = raw == null ? NaN : Number(raw);
36
194
  const range = { min: CHECKIN_MIN, max: CHECKIN_MAX };
37
- if (!Number.isInteger(v)) { c.err(t('usage', range, c.env)); return 2; }
38
- if (v < CHECKIN_MIN || v > CHECKIN_MAX) { c.err(t('range', range, c.env)); return 2; }
195
+ if (!Number.isInteger(v)) { c.err(t('checkinUsage', range, c.env)); return 2; }
196
+ if (v < CHECKIN_MIN || v > CHECKIN_MAX) { c.err(t('checkinRange', range, c.env)); return 2; }
39
197
  const data = await postCheckin(c.baseUrl, c.credOpts, v, { fetchImpl: c.fetchImpl });
40
198
  noteReported(v, c.credOpts, (c.deps.nowMs || Date.now)());
41
- c.log(c.flags.json ? JSON.stringify({ ok: true, ...(data || {}) }) : t('ok', { n: v }, c.env));
199
+ c.log(c.flags.json ? JSON.stringify({ ok: true, ...(data || {}) }) : t('checkinOk', { n: v }, c.env));
42
200
  return 0;
43
201
  }
44
202
 
45
- /** anytowork setup checkin <minutes> */
203
+ /**
204
+ * anytowork setup check | test-wake | ack | checkin
205
+ * @param {object} p { command, positionals, flags, baseUrl, credOpts, fetchImpl, deps, log, err, env }
206
+ */
46
207
  export async function runSetup(p) {
47
- const c = { flags: p.flags, baseUrl: p.baseUrl, credOpts: p.credOpts, fetchImpl: p.fetchImpl, deps: p.deps || {}, log: p.log, err: p.err, env: p.env || process.env };
48
- return runCheckin(c, p.positionals[2]);
208
+ const c = {
209
+ flags: p.flags, baseUrl: p.baseUrl, credOpts: p.credOpts, fetchImpl: p.fetchImpl,
210
+ deps: p.deps || {}, log: p.log, err: p.err, env: p.env || process.env,
211
+ };
212
+ const sub = p.command.slice('setup:'.length);
213
+ const arg = p.positionals[2];
214
+ if (sub === 'check') return runCheck(c);
215
+ if (sub === 'test-wake') return runTestWake(c);
216
+ if (sub === 'ack') return runAck(c, arg);
217
+ return runCheckin(c, arg);
49
218
  }
@@ -0,0 +1,129 @@
1
+ // v0.37: "settings after connecting" in the command output: the one-line 🎯 reminder the platform asks for
2
+ // (poll / listen / chat read carry `setup_hint`), and the wake-up test event (`wake_test`).
3
+ //
4
+ // The platform decides WHAT is missing and how often to say it (at most once a day per item); the CLI only prints.
5
+ // Plain words, no product names: it talks to the Agent that runs the command.
6
+
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import { atomicWriteFile } from './atomic-write.js';
10
+ import { resolveCredDir } from './profile.js';
11
+ import { pickLang } from './model-pledge.js';
12
+
13
+ export const SETUP_DOC_URL = {
14
+ zh: 'https://a2a.linger.chimap.cn/docs/guide/agent-setup',
15
+ en: 'https://a2a.linger.chimap.cn/en/docs/guide/agent-setup',
16
+ };
17
+
18
+ const ITEM_LABEL = {
19
+ wake: { zh: '能被叫醒', en: 'be wakeable' },
20
+ model: { zh: '说明你用的模型', en: 'say which models you use' },
21
+ cli: { zh: '命令行需要升级', en: 'the command line needs an upgrade' },
22
+ checkin: { zh: '如实报你的检查间隔', en: 'report how often you check in' },
23
+ };
24
+
25
+ const TEXT = {
26
+ hint: {
27
+ zh: '🎯 接好后的设置还差:{items}。按 {url} 补上,做完告诉主人。',
28
+ en: '🎯 Settings after connecting still missing: {items}. Finish them following {url}, then tell your owner.',
29
+ },
30
+ stale: {
31
+ zh: '🎯 你报的检查间隔是 {n} 分钟,但已经很久没出现了。请核对实际间隔,并重新上报:anytowork setup checkin <分钟>。',
32
+ en: '🎯 You reported checking in every {n} minutes, but you have not shown up for a long time. Check the real interval and report it again: anytowork setup checkin <minutes>.',
33
+ },
34
+ wakeTest: {
35
+ zh: '🎯 这是主人发起的叫醒测试:请运行 anytowork setup ack {code},让主人看到你已被叫醒。',
36
+ en: '🎯 Your owner started a wake-up test: run anytowork setup ack {code} so they can see you were woken.',
37
+ },
38
+ };
39
+
40
+ function fill(s, vars) {
41
+ let out = s;
42
+ for (const [k, v] of Object.entries(vars)) out = out.split(`{${k}}`).join(String(v));
43
+ return out;
44
+ }
45
+
46
+ /**
47
+ * The 🎯 lines for a `setup_hint` block ({items, url}); [] when there is nothing to say (old platform, nothing missing).
48
+ * An item is a key ("wake") or an object ({key, state, every_minutes}). A ready-made `text` from the platform wins.
49
+ */
50
+ export function setupHintLines(hint, env = process.env) {
51
+ if (!hint || typeof hint !== 'object') return [];
52
+ const lang = pickLang(env);
53
+ if (typeof hint.text === 'string' && hint.text.trim()) return [hint.text.trim()];
54
+ const items = Array.isArray(hint.items) ? hint.items : [];
55
+ const lines = [];
56
+ const labels = [];
57
+ for (const it of items) {
58
+ const obj = it && typeof it === 'object' ? it : { key: it };
59
+ const key = String(obj.key || '');
60
+ if (!ITEM_LABEL[key]) continue;
61
+ if (key === 'checkin' && obj.state === 'stale') {
62
+ lines.push(fill(TEXT.stale[lang], { n: obj.every_minutes != null ? obj.every_minutes : '?' }));
63
+ continue;
64
+ }
65
+ labels.push(ITEM_LABEL[key][lang]);
66
+ }
67
+ if (labels.length) {
68
+ const url = typeof hint.url === 'string' && hint.url ? hint.url : SETUP_DOC_URL[lang];
69
+ lines.unshift(fill(TEXT.hint[lang], { items: labels.join(lang === 'en' ? ', ' : '、'), url }));
70
+ }
71
+ return lines;
72
+ }
73
+
74
+ // ---------------------------------------------------------------- wake-up test event
75
+
76
+ const wakeTestFile = (credOpts) => path.join(resolveCredDir(credOpts || {}), 'wake-test.json');
77
+
78
+ /** The wake-up test the platform started for this Agent: { test_id, code, deadline_at } (payload of `wake_test`). */
79
+ export function isWakeTestEvent(e) {
80
+ return !!e && e.event_type === 'wake_test';
81
+ }
82
+
83
+ /** The one-time code of a test: the platform calls it `code`; `nonce` is the name the contract first used. */
84
+ export function testCode(p) {
85
+ const v = (p && (p.code != null ? p.code : p.nonce)) || '';
86
+ return String(v);
87
+ }
88
+
89
+ /** Remember the latest wake-up test, so `setup ack <code>` can find its id. Best-effort; never throws. */
90
+ export function noteWakeTests(events, credOpts, nowMs = Date.now()) {
91
+ try {
92
+ let last = null;
93
+ for (const e of events || []) {
94
+ if (!isWakeTestEvent(e)) continue;
95
+ const p = e.payload || {};
96
+ const code = testCode(p);
97
+ if (p.test_id && code) last = { test_id: String(p.test_id), nonce: code, deadline_at: p.deadline_at || null, seen_at: nowMs };
98
+ }
99
+ if (last) atomicWriteFile(wakeTestFile(credOpts), JSON.stringify(last), 0o600);
100
+ return last;
101
+ } catch { return null; }
102
+ }
103
+
104
+ /** The remembered test, or null. */
105
+ export function readWakeTest(credOpts) {
106
+ try {
107
+ const o = JSON.parse(fs.readFileSync(wakeTestFile(credOpts), 'utf8'));
108
+ return o && o.test_id ? o : null;
109
+ } catch { return null; }
110
+ }
111
+
112
+ /** The 🎯 line printed under a `wake_test` event (the platform's own `next_action` is used when it sent one). */
113
+ export function wakeTestLines(e, env = process.env) {
114
+ if (!isWakeTestEvent(e)) return [];
115
+ const p = e.payload || {};
116
+ const code = testCode(p);
117
+ if (!code) return [];
118
+ return [` ${fill(TEXT.wakeTest[pickLang(env)], { code })}`];
119
+ }
120
+
121
+ /** The same sentence as the prompt of a woken Agent (always-on listener: it is started by this very event). */
122
+ export function wakeTestPrompt(payload, env = process.env) {
123
+ const p = payload || {};
124
+ const lang = pickLang(env);
125
+ const line = fill(TEXT.wakeTest[lang], { code: testCode(p) });
126
+ return lang === 'en'
127
+ ? `[AnytoWork] This is a wake-up test, not a task.\n${line}`
128
+ : `[AnytoWork] 这是一次叫醒测试,不是任务。\n${line}`;
129
+ }