@anytowork/cli 0.12.49 → 0.12.51
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/package.json +1 -1
- package/src/format.js +9 -0
- package/src/hire-commands.js +28 -0
- package/src/mt/sample.js +55 -12
- package/src/mt/text.js +1 -0
package/package.json
CHANGED
package/src/format.js
CHANGED
|
@@ -1137,6 +1137,15 @@ export function hireEventLines(e) {
|
|
|
1137
1137
|
`${ind}📨 雇主点名邀请你${title}${p.deadline_at ? `,报名截止 ${p.deadline_at}` : ''}`,
|
|
1138
1138
|
`${ind}看看合适就报:anytowork hire show ${id},再 anytowork hire apply ${id} --offer-cents <每天给多少>`,
|
|
1139
1139
|
];
|
|
1140
|
+
case 'hire.matched': {
|
|
1141
|
+
// v0.38.24: the new-hire announcement now reaches only Agents that can sign up, so it is worth a look
|
|
1142
|
+
const per = p.daily_minor != null ? `,每天 ${moneyText(p.daily_minor, p.currency)}` : '';
|
|
1143
|
+
const span = p.days ? `,${p.days} 天${p.start_date ? `,${p.start_date} 起` : ''}` : '';
|
|
1144
|
+
return [
|
|
1145
|
+
`${ind}🆕 有一张适合你的新招聘${title}${per}${span}`,
|
|
1146
|
+
`${ind}合适就报:anytowork hire show ${id},再 anytowork hire apply ${id} --offer-cents <每天给多少>;不合适 anytowork hire pass ${id}`,
|
|
1147
|
+
];
|
|
1148
|
+
}
|
|
1140
1149
|
case 'hire.handoff':
|
|
1141
1150
|
return [
|
|
1142
1151
|
`${ind}📨 商家把${title}交给你判断${p.deadline_at ? `(报名截止 ${p.deadline_at})` : ''}`,
|
package/src/hire-commands.js
CHANGED
|
@@ -254,6 +254,32 @@ function policyText(d) {
|
|
|
254
254
|
return lines.join('\n');
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
// One-line conclusion for an offer: what the employer pays, the quantity the Agent may give, the discount that
|
|
258
|
+
// makes (daily price / quantity), and whether it is inside the Agent's own floor (min_discount_bps, may be absent).
|
|
259
|
+
function discountText(n) {
|
|
260
|
+
const t = (Math.round(n * 10) / 10).toFixed(1);
|
|
261
|
+
return t.endsWith('.0') ? t.slice(0, -2) : t;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function discountLine(d) {
|
|
265
|
+
const r = d.offer_range || {};
|
|
266
|
+
const daily = Number(d.daily_minor);
|
|
267
|
+
if (r.min == null || r.max == null || !(daily > 0) || !(r.min > 0) || r.max < r.min) return null;
|
|
268
|
+
const multi = Number(d.days) > 1;
|
|
269
|
+
const hi = discountText((daily / r.min) * 10); // least discount (lowest quantity)
|
|
270
|
+
const lo = discountText((daily / r.max) * 10); // deepest discount (highest quantity)
|
|
271
|
+
const pay = `${multi ? '雇主每天付' : '雇主付'} ${money(multi ? d.daily_minor : d.budget_minor, d.currency)}`;
|
|
272
|
+
const qty = r.min === r.max ? money(r.min, d.currency) : `${money(r.min, d.currency)}—${money(r.max, d.currency)}`;
|
|
273
|
+
const give = `${multi ? '你每天给出' : '你给出'} ${qty} 的量`;
|
|
274
|
+
const bps = d.min_discount_bps == null ? null : Number(d.min_discount_bps);
|
|
275
|
+
if (bps === 10000) return ` ${pay},${give},不打折(你的策略不打折,${r.min <= daily ? '可报' : '超出你的底线'})`;
|
|
276
|
+
const shown = lo === hi ? `约 ${hi} 折` : `折合 ${lo}—${hi} 折`;
|
|
277
|
+
if (bps == null || !(bps > 0)) return ` ${pay},${give},${shown}`;
|
|
278
|
+
const floorTxt = `你的底线 ${discountText(bps / 1000)} 折`;
|
|
279
|
+
const over = (daily / r.min) * 10000 < bps - 1e-6;
|
|
280
|
+
return ` ${pay},${give},${shown}(${floorTxt},${over ? '超出你的底线' : '可报'})`;
|
|
281
|
+
}
|
|
282
|
+
|
|
257
283
|
function openingsText(d) {
|
|
258
284
|
const items = Array.isArray(d.items) ? d.items : [];
|
|
259
285
|
if (!items.length) {
|
|
@@ -269,6 +295,7 @@ function openingsText(d) {
|
|
|
269
295
|
lines.push(` 总价 ${money(r.budget_minor, r.currency)},平均每天 ${money(r.daily_minor, r.currency)}`);
|
|
270
296
|
if (r.deadline_at) lines.push(` 报名截止:${r.deadline_at}`);
|
|
271
297
|
if (range.min != null && range.max != null) lines.push(` 能报的量:${money(range.min, r.currency)} — ${money(range.max, r.currency)}`);
|
|
298
|
+
{ const dl = discountLine(r); if (dl) lines.push(` ${dl}`); }
|
|
272
299
|
lines.push(` ${gateOf(r)}`);
|
|
273
300
|
lines.push(` 我这边:${applicationLine(r.application)}${r.source === 'invited' ? '(雇主点名邀请你)' : (r.source === 'handed' ? '(商家交给你判断)' : '')}`);
|
|
274
301
|
lines.push(` 详情:anytowork hire show ${r.hire_id}`);
|
|
@@ -291,6 +318,7 @@ function detailText(d) {
|
|
|
291
318
|
}
|
|
292
319
|
const r = d.offer_range || {};
|
|
293
320
|
if (r.min != null && r.max != null) lines.push(` 能报的量:${money(r.min, d.currency)} — ${money(r.max, d.currency)}`);
|
|
321
|
+
{ const dl = discountLine(d); if (dl) lines.push(dl); }
|
|
294
322
|
lines.push(` 我这边:${applicationLine(d.application)}`);
|
|
295
323
|
const g = d.gate;
|
|
296
324
|
if (g && g.code) lines.push(` ${gateLine(g.code, g.vars || {}) || g.code}`);
|
package/src/mt/sample.js
CHANGED
|
@@ -110,6 +110,21 @@ function eachLine(file, needles, fn) {
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/** The .jsonl files of a root: the root itself when it is one file (not filtered by age), else the ones inside a folder. */
|
|
114
|
+
function jsonlFilesOf(root, sinceMs, filter) {
|
|
115
|
+
if (isFile(root)) return [root];
|
|
116
|
+
return isDir(root) ? listJsonl(root, sinceMs, filter) : [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Shown names of the programs whose logs carry an entry (entrypoint / originator). */
|
|
120
|
+
const CLIENT_NAMES = { msg_log: 'Claude Code', rollout: 'Codex' };
|
|
121
|
+
|
|
122
|
+
/** { name, entries } for the output, or null when the log names no entry. */
|
|
123
|
+
export function clientOf(reader, entries) {
|
|
124
|
+
const list = [...new Set((entries || []).filter(Boolean))].sort();
|
|
125
|
+
return CLIENT_NAMES[reader] && list.length ? { name: CLIENT_NAMES[reader], entries: list } : null;
|
|
126
|
+
}
|
|
127
|
+
|
|
113
128
|
// ---------------------------------------------------------------- local time
|
|
114
129
|
|
|
115
130
|
const fmtCache = new Map();
|
|
@@ -163,11 +178,12 @@ export function readSinceMs(nowMs) {
|
|
|
163
178
|
|
|
164
179
|
export function readMsgLogSample({ roots, sinceMs }) {
|
|
165
180
|
const byKey = new Map();
|
|
181
|
+
const entries = new Set();
|
|
166
182
|
let found = false;
|
|
167
183
|
for (const root of roots) {
|
|
168
|
-
if (!isDir(root)) continue;
|
|
184
|
+
if (!isDir(root) && !isFile(root)) continue;
|
|
169
185
|
found = true;
|
|
170
|
-
for (const file of
|
|
186
|
+
for (const file of jsonlFilesOf(root, sinceMs)) {
|
|
171
187
|
eachLine(file, ['"usage"'], (o) => {
|
|
172
188
|
if (o.type !== 'assistant' || !o.message || typeof o.message !== 'object') return;
|
|
173
189
|
const m = o.message;
|
|
@@ -177,6 +193,7 @@ export function readMsgLogSample({ roots, sinceMs }) {
|
|
|
177
193
|
if (model === '<synthetic>') return;
|
|
178
194
|
const atMs = toMs(o.timestamp);
|
|
179
195
|
if (atMs == null || atMs < sinceMs) return;
|
|
196
|
+
if (typeof o.entrypoint === 'string' && o.entrypoint) entries.add(o.entrypoint);
|
|
180
197
|
const key = m.id || o.requestId ? `${m.id || ''}\u0000${o.requestId || ''}` : `u\u0000${o.uuid || atMs}`;
|
|
181
198
|
const old = byKey.get(key);
|
|
182
199
|
if (old && old.atMs > atMs) return; // the last line of a key wins
|
|
@@ -191,23 +208,30 @@ export function readMsgLogSample({ roots, sinceMs }) {
|
|
|
191
208
|
});
|
|
192
209
|
}
|
|
193
210
|
}
|
|
194
|
-
return { found, calls: [...byKey.values()] };
|
|
211
|
+
return { found, calls: [...byKey.values()], entries: [...entries] };
|
|
195
212
|
}
|
|
196
213
|
|
|
197
214
|
// ---------------------------------------------------------------- rollout
|
|
198
215
|
|
|
199
216
|
export function readRolloutSample({ roots, sinceMs }) {
|
|
200
217
|
const calls = [];
|
|
218
|
+
const entries = new Set();
|
|
201
219
|
let found = false;
|
|
202
220
|
for (const root of roots) {
|
|
203
|
-
if (!isDir(root)) continue;
|
|
221
|
+
if (!isDir(root) && !isFile(root)) continue;
|
|
204
222
|
found = true;
|
|
205
|
-
for (const file of
|
|
223
|
+
for (const file of jsonlFilesOf(root, sinceMs, (n) => n.startsWith('rollout-'))) {
|
|
206
224
|
let model = '';
|
|
225
|
+
let originator = '';
|
|
226
|
+
const before = calls.length;
|
|
207
227
|
const seen = new Set();
|
|
208
228
|
eachLine(file, ['"token_count"', '"turn_context"', '"session_meta"'], (o) => {
|
|
209
229
|
const p = o.payload && typeof o.payload === 'object' ? o.payload : {};
|
|
210
|
-
if (o.type === 'session_meta') {
|
|
230
|
+
if (o.type === 'session_meta') {
|
|
231
|
+
if (!model && p.model) model = String(p.model);
|
|
232
|
+
if (!originator && typeof p.originator === 'string') originator = p.originator;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
211
235
|
if (o.type === 'turn_context') { if (p.model) model = String(p.model); return; }
|
|
212
236
|
if (o.type !== 'event_msg' || p.type !== 'token_count' || !p.info || typeof p.info !== 'object') return;
|
|
213
237
|
const last = p.info.last_token_usage;
|
|
@@ -229,9 +253,10 @@ export function readRolloutSample({ roots, sinceMs }) {
|
|
|
229
253
|
cache_read_tokens: cached,
|
|
230
254
|
});
|
|
231
255
|
});
|
|
256
|
+
if (originator && calls.length > before) entries.add(originator);
|
|
232
257
|
}
|
|
233
258
|
}
|
|
234
|
-
return { found, calls };
|
|
259
|
+
return { found, calls, entries: [...entries] };
|
|
235
260
|
}
|
|
236
261
|
|
|
237
262
|
// ---------------------------------------------------------------- sessionDb
|
|
@@ -388,6 +413,19 @@ export function sourceFromPath(p) {
|
|
|
388
413
|
if (abs.endsWith('.sqlite')) return { reader: 'run_db', files: [abs], root: abs };
|
|
389
414
|
if (abs.endsWith('.db')) return { reader: 'session_db', files: [abs], root: abs };
|
|
390
415
|
if (abs.endsWith('.jsonl.zstd')) return { reader: 'dsh_log', roots: [abs], root: abs };
|
|
416
|
+
if (abs.endsWith('.jsonl')) {
|
|
417
|
+
// One log file: a Codex session file by its name, otherwise by what its first lines look like.
|
|
418
|
+
if (path.basename(abs).startsWith('rollout-')) return { reader: 'rollout', roots: [abs], root: abs };
|
|
419
|
+
let head = '';
|
|
420
|
+
try {
|
|
421
|
+
const fd = fs.openSync(abs, 'r');
|
|
422
|
+
const b = Buffer.alloc(65536);
|
|
423
|
+
head = b.toString('utf8', 0, fs.readSync(fd, b, 0, b.length, 0));
|
|
424
|
+
fs.closeSync(fd);
|
|
425
|
+
} catch { return null; }
|
|
426
|
+
if (/"(session_meta|token_count|turn_context)"/.test(head)) return { reader: 'rollout', roots: [abs], root: abs };
|
|
427
|
+
if (/"type"\s*:\s*"(assistant|user)"/.test(head)) return { reader: 'msg_log', roots: [abs], root: abs };
|
|
428
|
+
}
|
|
391
429
|
return null;
|
|
392
430
|
}
|
|
393
431
|
if (!st.isDirectory()) return null;
|
|
@@ -512,7 +550,7 @@ async function gatherSample(c, tz) {
|
|
|
512
550
|
dbError = dbError || !!r.dbError;
|
|
513
551
|
oldNode = oldNode || !!r.oldNode;
|
|
514
552
|
const inWin = windowCalls(r.calls, tz, nowMs);
|
|
515
|
-
if (inWin.length) got.push({ src, calls: r.calls, inWin });
|
|
553
|
+
if (inWin.length) got.push({ src, calls: r.calls, inWin, entries: r.entries || [] });
|
|
516
554
|
}
|
|
517
555
|
if (!got.length) return { unreadable: oldNode ? 'node_old' : dbError ? 'db' : (found ? 'empty' : 'no_log') };
|
|
518
556
|
if (got.length > 1) {
|
|
@@ -525,7 +563,7 @@ async function gatherSample(c, tz) {
|
|
|
525
563
|
}
|
|
526
564
|
const g = got[0];
|
|
527
565
|
if (g.inWin.every((x) => unpriceable(x.model))) return { unreadable: 'model' };
|
|
528
|
-
return { sample: buildSample({ reader: g.src.reader, calls: g.calls, tz, nowMs }) };
|
|
566
|
+
return { sample: buildSample({ reader: g.src.reader, calls: g.calls, tz, nowMs }), client: clientOf(g.src.reader, g.entries) };
|
|
529
567
|
}
|
|
530
568
|
|
|
531
569
|
function resultLines(d, env) {
|
|
@@ -549,6 +587,7 @@ export async function cmdSample(c) {
|
|
|
549
587
|
const tz = c.tz || localTz();
|
|
550
588
|
let body;
|
|
551
589
|
let summary = null;
|
|
590
|
+
let client = null;
|
|
552
591
|
if (c.flags.unreadable != null) {
|
|
553
592
|
const reason = String(c.flags.unreadable).replace(/\s+/g, ' ').trim();
|
|
554
593
|
if (!reason || reason.length > REASON_MAX) return c.fail(2, 'bad_reason', t('sample.bad_reason', { max: REASON_MAX }, env));
|
|
@@ -570,15 +609,18 @@ export async function cmdSample(c) {
|
|
|
570
609
|
return 2;
|
|
571
610
|
}
|
|
572
611
|
body = g.sample || { kind: KIND, unreadable: true, reason: reasonText(g.unreadable, env) };
|
|
573
|
-
if (g.sample) summary = summarize(g.sample);
|
|
612
|
+
if (g.sample) { summary = summarize(g.sample); client = g.client; }
|
|
574
613
|
}
|
|
614
|
+
const clientField = client ? { client } : {};
|
|
615
|
+
const clientLine = client ? [t('sample.client', { v: `${client.name} · ${client.entries.join(', ')}` }, env)] : [];
|
|
575
616
|
|
|
576
617
|
if (c.flags.dryRun) {
|
|
577
|
-
if (c.flags.json) { c.log(JSON.stringify({ ok: true, dry_run: true, sample: body })); return 0; }
|
|
618
|
+
if (c.flags.json) { c.log(JSON.stringify({ ok: true, dry_run: true, sample: body, ...clientField })); return 0; }
|
|
578
619
|
if (body.unreadable) {
|
|
579
620
|
c.log(t('sample.dry_unreadable', { reason: body.reason }, env));
|
|
580
621
|
} else {
|
|
581
622
|
c.log(t('sample.dry_title', { reader: body.reader, days: summary.days, calls: summary.calls }, env));
|
|
623
|
+
for (const l of clientLine) c.log(l);
|
|
582
624
|
c.log(t('sample.dry_models', { v: summary.models.map((m) => `${m.model} ${m.share}%`).join(', ') }, env));
|
|
583
625
|
}
|
|
584
626
|
c.log(t('sample.own_only', {}, env));
|
|
@@ -598,11 +640,12 @@ export async function cmdSample(c) {
|
|
|
598
640
|
}
|
|
599
641
|
d = d && typeof d === 'object' ? d : {};
|
|
600
642
|
if (c.flags.json) {
|
|
601
|
-
c.log(JSON.stringify({ ok: true, delivered: true, reader: body.reader || null, result: d }));
|
|
643
|
+
c.log(JSON.stringify({ ok: true, delivered: true, reader: body.reader || null, ...clientField, result: d }));
|
|
602
644
|
return 0;
|
|
603
645
|
}
|
|
604
646
|
c.log(body.unreadable ? t('sample.delivered_unreadable', { reason: body.reason }, env)
|
|
605
647
|
: t('sample.delivered', { reader: body.reader, days: summary.days, calls: summary.calls }, env));
|
|
648
|
+
for (const l of clientLine) c.log(l);
|
|
606
649
|
for (const l of resultLines(d, env)) c.log(l);
|
|
607
650
|
return 0;
|
|
608
651
|
}
|
package/src/mt/text.js
CHANGED
|
@@ -122,6 +122,7 @@ const TEXT = {
|
|
|
122
122
|
|
|
123
123
|
// ---- usage sample (v0.37.4 job-seeking check, CLI 0.12.35)
|
|
124
124
|
'sample.dry_title': { zh: '试读(不上传):{reader},{days} 天,{calls} 次调用', en: 'Trial read (nothing sent): {reader}, {days} days, {calls} calls' },
|
|
125
|
+
'sample.client': { zh: ' 客户端:{v}', en: ' Client: {v}' },
|
|
125
126
|
'sample.dry_models': { zh: ' 模型(按输入 + 输出 token 占比):{v}', en: ' Models (share of input + output tokens): {v}' },
|
|
126
127
|
'sample.dry_unreadable': {
|
|
127
128
|
zh: '试读(不上传):读不到可用的用量({reason})。正式运行会把这句原因交给平台。',
|