@anytowork/cli 0.12.50 → 0.12.52

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anytowork/cli",
3
- "version": "0.12.50",
3
+ "version": "0.12.52",
4
4
  "description": "AnytoWork 平台命令行工具——让任何能执行 shell 命令的 Agent 用一条命令接入 AnytoWork:登录、发单接单、管理能力。",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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/dsh.js CHANGED
@@ -114,8 +114,11 @@ function applyEvent(st, o) {
114
114
  if (!o || typeof o !== 'object') return;
115
115
  const d = o.data && typeof o.data === 'object' ? o.data : {};
116
116
  if (o.type === 'session') {
117
- if (d.id) st.sid = String(d.id);
118
- if (typeof d.cwd === 'string') st.cwd = d.cwd;
117
+ // v0.38.33: the real log keeps id and cwd at the top level of the session line (not under `data`); both read.
118
+ const sid = o.id || d.id;
119
+ const cwd = typeof o.cwd === 'string' ? o.cwd : d.cwd;
120
+ if (sid) st.sid = String(sid);
121
+ if (typeof cwd === 'string') st.cwd = cwd;
119
122
  return;
120
123
  }
121
124
  if (o.type !== 'assistant/message') return;
package/src/mt/inrun.js CHANGED
@@ -248,7 +248,11 @@ export class RunUsageTracker {
248
248
  try {
249
249
  for (const c of src.read().calls) {
250
250
  if (c.seenMs < since || c.seenMs > until || c.seenMs > now - settleMs) continue;
251
- if (!c.cwd || !dirMatches(c.cwd, r.dirs, home)) continue;
251
+ if (!c.cwd) continue;
252
+ // v0.38.33: DSH records the folder it was started from (the home folder), not the Agent's work folder. A run that
253
+ // the start command names as dsh takes the dsh calls made from the home folder inside its own time window.
254
+ const harnessHome = src.program === 'dsh' && r.prog === 'dsh' && norm(c.cwd) === norm(home);
255
+ if (!harnessHome && !dirMatches(c.cwd, r.dirs, home)) continue;
252
256
  rows.push(callRow(c, { program: src.program, reader: src.reader, attribution: attributionOfCalls, taskRef: r.taskRef, workdirId: workdirOf(c.cwd) }));
253
257
  }
254
258
  } catch { /* one unreadable log never blocks the others */ }
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 listJsonl(root, sinceMs)) {
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 listJsonl(root, sinceMs, (n) => n.startsWith('rollout-'))) {
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') { if (!model && p.model) model = String(p.model); return; }
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})。正式运行会把这句原因交给平台。',