@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
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// v0.36.0: readers for the usual model-call log files on this computer (contract v1 section 1, MT-5).
|
|
2
|
+
//
|
|
3
|
+
// What they do: walk the log folders that common Agents keep under the home folder, and turn each model call into one
|
|
4
|
+
// metadata row: call id, conversation id, model, token counts, time and the working directory of the session.
|
|
5
|
+
// What they never do: keep or send prompts, answers, tool input/output or file contents. A whole log line has to be
|
|
6
|
+
// parsed as JSON, but only the fields listed above are copied out of it.
|
|
7
|
+
//
|
|
8
|
+
// The reader names below are internal; nothing user-facing names a product or a log framework (README / --help /
|
|
9
|
+
// output say "the usual log files on this computer"). When nothing can be read, the Agent is asked to convert its own
|
|
10
|
+
// records to the standard format and use `usage push`.
|
|
11
|
+
//
|
|
12
|
+
// Readers:
|
|
13
|
+
// msgLog JSON Lines per session; assistant lines carry message.id / message.model / message.usage and cwd.
|
|
14
|
+
// One reply can be split over several lines with the same message id: they are merged (max per counter).
|
|
15
|
+
// rollout JSON Lines per session; a session_meta line (id, cwd, provider), turn_context lines (model, cwd) and
|
|
16
|
+
// token_count events with last_token_usage. Input there includes cached input: it is split out.
|
|
17
|
+
// sessionDb a SQLite file with one row per session (totals only). It becomes a summary row (no per-call rate) and is
|
|
18
|
+
// read only when this Node has the built-in SQLite module and the session has ended.
|
|
19
|
+
|
|
20
|
+
import fs from 'node:fs';
|
|
21
|
+
import os from 'node:os';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { createHash } from 'node:crypto';
|
|
24
|
+
|
|
25
|
+
const MAX_DEPTH = 6;
|
|
26
|
+
|
|
27
|
+
/** Lower-case provider guessed from the model name when the log does not say it. */
|
|
28
|
+
export function guessProvider(model) {
|
|
29
|
+
const m = String(model || '').toLowerCase();
|
|
30
|
+
if (/claude|anthropic/.test(m)) return 'anthropic';
|
|
31
|
+
if (/^(gpt|o\d|chatgpt|text-embedding|dall-e|codex)/.test(m) || m.includes('openai')) return 'openai';
|
|
32
|
+
if (m.includes('gemini') || m.includes('gemma')) return 'google';
|
|
33
|
+
if (m.includes('deepseek')) return 'deepseek';
|
|
34
|
+
if (m.includes('qwen') || m.includes('qwq')) return 'alibaba';
|
|
35
|
+
if (m.includes('kimi') || m.includes('moonshot')) return 'moonshot';
|
|
36
|
+
if (m.includes('glm') || m.includes('zhipu')) return 'zhipu';
|
|
37
|
+
if (m.includes('doubao') || m.includes('seed')) return 'bytedance';
|
|
38
|
+
if (m.includes('minimax') || m.includes('abab')) return 'minimax';
|
|
39
|
+
if (m.includes('grok')) return 'xai';
|
|
40
|
+
if (m.includes('llama')) return 'meta';
|
|
41
|
+
if (m.includes('mistral') || m.includes('codestral')) return 'mistral';
|
|
42
|
+
return 'unknown';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function int(v) {
|
|
46
|
+
const n = Number(v);
|
|
47
|
+
return Number.isFinite(n) && n >= 0 ? Math.floor(n) : 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function iso(v) {
|
|
51
|
+
if (v == null || v === '') return null;
|
|
52
|
+
const d = typeof v === 'number' ? new Date(v < 1e12 ? v * 1000 : v) : new Date(String(v));
|
|
53
|
+
return Number.isNaN(d.getTime()) ? null : d.toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** All *.jsonl files under `root` changed at or after sinceMs (by mtime). */
|
|
57
|
+
export function listJsonl(root, sinceMs, filter = () => true) {
|
|
58
|
+
const out = [];
|
|
59
|
+
const walk = (dir, depth) => {
|
|
60
|
+
let entries;
|
|
61
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
|
62
|
+
for (const e of entries) {
|
|
63
|
+
const p = path.join(dir, e.name);
|
|
64
|
+
if (e.isDirectory()) { if (depth < MAX_DEPTH) walk(p, depth + 1); continue; }
|
|
65
|
+
if (!e.isFile() || !e.name.endsWith('.jsonl') || !filter(e.name)) continue;
|
|
66
|
+
try { if (fs.statSync(p).mtimeMs >= sinceMs) out.push(p); } catch { /* vanished */ }
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
walk(root, 0);
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function eachJsonLine(file, fn) {
|
|
74
|
+
let text;
|
|
75
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return; }
|
|
76
|
+
for (const line of text.split('\n')) {
|
|
77
|
+
if (!line || line[0] !== '{') continue;
|
|
78
|
+
let o;
|
|
79
|
+
try { o = JSON.parse(line); } catch { continue; }
|
|
80
|
+
fn(o);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function mergeInto(map, row) {
|
|
85
|
+
const old = map.get(row.call_id);
|
|
86
|
+
if (!old) { map.set(row.call_id, row); return; }
|
|
87
|
+
for (const k of ['input_tokens', 'output_tokens', 'cache_write_tokens', 'cache_read_tokens']) old[k] = Math.max(old[k], row[k]);
|
|
88
|
+
if (row.started_at && (!old.started_at || row.started_at < old.started_at)) old.started_at = row.started_at;
|
|
89
|
+
const end = row.ended_at || row.started_at;
|
|
90
|
+
if (end && end > (old.ended_at || old.started_at)) old.ended_at = end;
|
|
91
|
+
old.seenMs = Math.max(old.seenMs, row.seenMs);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ---------------------------------------------------------------- msgLog
|
|
95
|
+
|
|
96
|
+
function msgLogRoots(home, env) {
|
|
97
|
+
const roots = [];
|
|
98
|
+
if (env.CLAUDE_CONFIG_DIR) for (const d of String(env.CLAUDE_CONFIG_DIR).split(',')) if (d.trim()) roots.push(path.join(d.trim(), 'projects'));
|
|
99
|
+
roots.push(path.join(home, '.claude', 'projects'), path.join(home, '.config', 'claude', 'projects'));
|
|
100
|
+
return [...new Set(roots)];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function readMsgLog({ home, env, sinceMs }) {
|
|
104
|
+
const calls = new Map();
|
|
105
|
+
let files = 0;
|
|
106
|
+
for (const root of msgLogRoots(home, env)) {
|
|
107
|
+
for (const file of listJsonl(root, sinceMs)) {
|
|
108
|
+
files += 1;
|
|
109
|
+
eachJsonLine(file, (o) => {
|
|
110
|
+
if (o.type !== 'assistant' || !o.message || typeof o.message !== 'object') return;
|
|
111
|
+
const m = o.message;
|
|
112
|
+
const u = m.usage;
|
|
113
|
+
if (!u || typeof u !== 'object' || !m.model || m.model === '<synthetic>') return;
|
|
114
|
+
const callId = m.id || o.requestId || o.uuid;
|
|
115
|
+
const at = iso(o.timestamp);
|
|
116
|
+
if (!callId || !at || !o.sessionId) return;
|
|
117
|
+
const seenMs = Date.parse(at);
|
|
118
|
+
if (seenMs < sinceMs) return;
|
|
119
|
+
mergeInto(calls, {
|
|
120
|
+
call_id: String(callId),
|
|
121
|
+
conversation_id: String(o.sessionId),
|
|
122
|
+
message_id: o.requestId && o.requestId !== callId ? String(o.requestId) : undefined,
|
|
123
|
+
provider: guessProvider(m.model),
|
|
124
|
+
model: String(m.model),
|
|
125
|
+
started_at: at,
|
|
126
|
+
ended_at: null,
|
|
127
|
+
input_tokens: int(u.input_tokens),
|
|
128
|
+
output_tokens: int(u.output_tokens),
|
|
129
|
+
cache_write_tokens: int(u.cache_creation_input_tokens),
|
|
130
|
+
cache_read_tokens: int(u.cache_read_input_tokens),
|
|
131
|
+
cwd: typeof o.cwd === 'string' ? o.cwd : null,
|
|
132
|
+
seenMs,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { calls: [...calls.values()], summaries: [], files };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ---------------------------------------------------------------- rollout
|
|
141
|
+
|
|
142
|
+
function rolloutRoots(home, env) {
|
|
143
|
+
const roots = [];
|
|
144
|
+
if (env.CODEX_HOME) roots.push(path.join(String(env.CODEX_HOME), 'sessions'));
|
|
145
|
+
roots.push(path.join(home, '.codex', 'sessions'));
|
|
146
|
+
return [...new Set(roots)];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function readRollout({ home, env, sinceMs }) {
|
|
150
|
+
const calls = new Map();
|
|
151
|
+
let files = 0;
|
|
152
|
+
for (const root of rolloutRoots(home, env)) {
|
|
153
|
+
for (const file of listJsonl(root, sinceMs, (n) => n.startsWith('rollout-'))) {
|
|
154
|
+
files += 1;
|
|
155
|
+
let sid = null;
|
|
156
|
+
let cwd = null;
|
|
157
|
+
let provider = null;
|
|
158
|
+
let model = null;
|
|
159
|
+
eachJsonLine(file, (o) => {
|
|
160
|
+
const p = o.payload && typeof o.payload === 'object' ? o.payload : {};
|
|
161
|
+
if (o.type === 'session_meta') {
|
|
162
|
+
sid = p.id || sid;
|
|
163
|
+
cwd = typeof p.cwd === 'string' ? p.cwd : cwd;
|
|
164
|
+
provider = p.model_provider || provider;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (o.type === 'turn_context') {
|
|
168
|
+
if (p.model) model = String(p.model);
|
|
169
|
+
if (typeof p.cwd === 'string') cwd = p.cwd;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (o.type !== 'event_msg' || p.type !== 'token_count' || !p.info) return;
|
|
173
|
+
const last = p.info.last_token_usage;
|
|
174
|
+
const total = p.info.total_token_usage;
|
|
175
|
+
const at = iso(o.timestamp);
|
|
176
|
+
if (!last || !sid || !model || !at) return;
|
|
177
|
+
const seenMs = Date.parse(at);
|
|
178
|
+
if (seenMs < sinceMs) return;
|
|
179
|
+
const cached = int(last.cached_input_tokens);
|
|
180
|
+
const totalTokens = total && total.total_tokens != null ? int(total.total_tokens) : null;
|
|
181
|
+
// A call id the log does not give: session + running total (stable when the file is read again).
|
|
182
|
+
const callId = `${sid}:${totalTokens != null ? totalTokens : at}`;
|
|
183
|
+
mergeInto(calls, {
|
|
184
|
+
call_id: callId,
|
|
185
|
+
conversation_id: String(sid),
|
|
186
|
+
provider: String(provider || guessProvider(model)).toLowerCase(),
|
|
187
|
+
model,
|
|
188
|
+
started_at: at,
|
|
189
|
+
ended_at: null,
|
|
190
|
+
input_tokens: Math.max(0, int(last.input_tokens) - cached),
|
|
191
|
+
output_tokens: int(last.output_tokens),
|
|
192
|
+
cache_write_tokens: 0,
|
|
193
|
+
cache_read_tokens: cached,
|
|
194
|
+
cwd,
|
|
195
|
+
seenMs,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return { calls: [...calls.values()], summaries: [], files };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ---------------------------------------------------------------- sessionDb
|
|
204
|
+
|
|
205
|
+
async function loadSqlite() {
|
|
206
|
+
// The built-in module prints an "experimental" warning on some Node versions: keep it off the Agent's screen.
|
|
207
|
+
const orig = process.emitWarning;
|
|
208
|
+
process.emitWarning = () => {};
|
|
209
|
+
try {
|
|
210
|
+
const mod = await import('node:sqlite');
|
|
211
|
+
return mod && mod.DatabaseSync ? mod.DatabaseSync : null;
|
|
212
|
+
} catch {
|
|
213
|
+
return null;
|
|
214
|
+
} finally {
|
|
215
|
+
process.emitWarning = orig;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function sessionDbFiles(home, env) {
|
|
220
|
+
const roots = [];
|
|
221
|
+
if (env.HERMES_HOME) roots.push(String(env.HERMES_HOME));
|
|
222
|
+
roots.push(path.join(home, '.hermes'));
|
|
223
|
+
return [...new Set(roots)].map((r) => path.join(r, 'state.db')).filter((f) => fs.existsSync(f));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function readSessionDb({ home, env, sinceMs, sqlite }) {
|
|
227
|
+
const files = sessionDbFiles(home, env);
|
|
228
|
+
if (!files.length) return { calls: [], summaries: [], files: 0 };
|
|
229
|
+
const DatabaseSync = sqlite === undefined ? await loadSqlite() : sqlite;
|
|
230
|
+
if (!DatabaseSync) return { calls: [], summaries: [], files: 0, unreadable: files.length };
|
|
231
|
+
const summaries = [];
|
|
232
|
+
for (const f of files) {
|
|
233
|
+
let db;
|
|
234
|
+
try {
|
|
235
|
+
db = new DatabaseSync(f, { readOnly: true });
|
|
236
|
+
const rows = db.prepare(
|
|
237
|
+
'SELECT id, model, billing_provider, cwd, started_at, ended_at, input_tokens, output_tokens, '
|
|
238
|
+
+ 'cache_read_tokens, cache_write_tokens FROM sessions WHERE ended_at IS NOT NULL AND ended_at >= ?',
|
|
239
|
+
).all(sinceMs / 1000);
|
|
240
|
+
for (const r of rows) {
|
|
241
|
+
const start = iso(r.started_at);
|
|
242
|
+
const end = iso(r.ended_at);
|
|
243
|
+
if (!r.model || !start || !end) continue;
|
|
244
|
+
summaries.push({
|
|
245
|
+
report_id: `s-${createHash('sha256').update(String(r.id)).digest('hex').slice(0, 32)}`,
|
|
246
|
+
period: { start, end, conversations: 1 },
|
|
247
|
+
item: {
|
|
248
|
+
model: String(r.model),
|
|
249
|
+
input_tokens: int(r.input_tokens),
|
|
250
|
+
output_tokens: int(r.output_tokens),
|
|
251
|
+
cache_write_tokens: int(r.cache_write_tokens),
|
|
252
|
+
cache_read_tokens: int(r.cache_read_tokens),
|
|
253
|
+
},
|
|
254
|
+
cwd: typeof r.cwd === 'string' ? r.cwd : null,
|
|
255
|
+
seenMs: Date.parse(end),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
} catch { /* a locked or different file: skip it */ } finally {
|
|
259
|
+
try { if (db) db.close(); } catch { /* ignore */ }
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return { calls: [], summaries, files: files.length };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Read every known log on this computer. `settleMs`: calls seen less than this long ago are left for the next run
|
|
267
|
+
* (a reply may still be streaming into the log).
|
|
268
|
+
* @returns {Promise<{calls, summaries, files}>}
|
|
269
|
+
*/
|
|
270
|
+
export async function readLocalLogs({ home = os.homedir(), env = process.env, sinceMs = 0, nowMs = Date.now(), settleMs = 60_000, sqlite } = {}) {
|
|
271
|
+
const parts = [readMsgLog({ home, env, sinceMs }), readRollout({ home, env, sinceMs }), await readSessionDb({ home, env, sinceMs, sqlite })];
|
|
272
|
+
const cut = nowMs - settleMs;
|
|
273
|
+
return {
|
|
274
|
+
calls: parts.flatMap((p) => p.calls).filter((c) => c.seenMs <= cut),
|
|
275
|
+
summaries: parts.flatMap((p) => p.summaries).filter((s) => s.seenMs <= cut),
|
|
276
|
+
files: parts.reduce((n, p) => n + p.files, 0),
|
|
277
|
+
};
|
|
278
|
+
}
|
package/src/mt/text.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// v0.36.0 model and usage trust (CLI 0.12.31): every line the model / workdir / usage commands print.
|
|
2
|
+
//
|
|
3
|
+
// Each key has a Chinese and an English wording; the language follows ANYTOWORK_LANG, else LC_ALL / LANG (same rule
|
|
4
|
+
// as model-pledge.js). Placeholders are written {name}.
|
|
5
|
+
// Wording rules: never name a particular Agent product or log framework (say "your Agent" / "the usual log files on
|
|
6
|
+
// this computer"); never describe how the platform checks or samples (contract v1 sections 8, 9, 11 stay internal).
|
|
7
|
+
|
|
8
|
+
import { pickLang } from '../model-pledge.js';
|
|
9
|
+
|
|
10
|
+
const TEXT = {
|
|
11
|
+
// ---- model policy
|
|
12
|
+
'policy.none': {
|
|
13
|
+
zh: '还没有设置默认模型策略。用 anytowork model policy set --primary <模型>[,<模型>] 设置(主力最多 2 个);报名时没单独说明,平台就用这一份。',
|
|
14
|
+
en: 'No default model policy yet. Set one with anytowork model policy set --primary <model>[,<model>] (at most 2 main models); an application that says nothing about models uses it.',
|
|
15
|
+
},
|
|
16
|
+
'policy.title': { zh: '我的默认模型策略(报名时没单独说明,平台就用这一份):', en: 'My default model policy (used when an application says nothing about models):' },
|
|
17
|
+
'policy.primary': { zh: ' 主力模型:{v}', en: ' Main models: {v}' },
|
|
18
|
+
'policy.role': { zh: ' {role}:{model}{text}', en: ' {role}: {model}{text}' },
|
|
19
|
+
'policy.note': { zh: ' 补充说明:{v}', en: ' Note: {v}' },
|
|
20
|
+
'policy.record_mode': { zh: ' 记录方式:{v}', en: ' Records: {v}' },
|
|
21
|
+
'policy.record_mode.call': { zh: '逐条记录', en: 'one line per call' },
|
|
22
|
+
'policy.record_mode.summary': { zh: '汇总上报', en: 'summaries' },
|
|
23
|
+
'policy.updated': { zh: ' 更新于 {at}', en: ' Updated {at}' },
|
|
24
|
+
'policy.suggest': {
|
|
25
|
+
zh: '本机最近常用的模型:{v}。这只是建议,确认后再用 anytowork model policy set 设置。',
|
|
26
|
+
en: 'Models used most on this computer lately: {v}. Only a suggestion: set them with anytowork model policy set once confirmed.',
|
|
27
|
+
},
|
|
28
|
+
'policy.saved': {
|
|
29
|
+
zh: '默认模型策略已保存,只影响之后没单独说明的报名;已报名、已签署的不受影响。每一单仍请在报名时按这一单的打算自己说明。',
|
|
30
|
+
en: 'Default model policy saved. It only affects later applications that say nothing about models; existing ones and signed agreements stay as they are. Still describe your plan for each job when you apply.',
|
|
31
|
+
},
|
|
32
|
+
'apply.need_primary': {
|
|
33
|
+
zh: '缺少主力模型:用 --role 或 --note 说明这一单的策略时,也要加 --primary <模型>[,<模型>](1 到 2 个)。',
|
|
34
|
+
en: 'Main models missing: when you describe this job with --role or --note, add --primary <model>[,<model>] (1 or 2) as well.',
|
|
35
|
+
},
|
|
36
|
+
'policy.need_primary': { zh: '缺少主力模型:加 --primary <模型>[,<模型>](1 到 2 个)。', en: 'Main models missing: add --primary <model>[,<model>] (1 or 2).' },
|
|
37
|
+
'policy.too_many_primary': { zh: '主力模型最多 2 个。', en: 'At most 2 main models.' },
|
|
38
|
+
'policy.bad_role': {
|
|
39
|
+
zh: '--role 写法是 <分工名>=<模型>[=<说明>],分工名自己起,例如 写代码=claude-sonnet-4-5 或 做图=gpt-image-1=只出示意图。',
|
|
40
|
+
en: '--role is written <name>=<model>[=<note>]; pick the name yourself, e.g. coding=claude-sonnet-4-5 or images=gpt-image-1=sketches only.',
|
|
41
|
+
},
|
|
42
|
+
'policy.bad_role_eq': {
|
|
43
|
+
zh: '--role 里最多两个「=」:分工名、模型名、说明里都不能再带「=」。',
|
|
44
|
+
en: '--role has at most two "=": the name, the model and the note cannot contain another one.',
|
|
45
|
+
},
|
|
46
|
+
'policy.bad_record_mode': { zh: '--record-mode 只能是 call 或 summary。', en: '--record-mode is call or summary.' },
|
|
47
|
+
'policy.err.invalid': { zh: '{where}不像模型名,请核对后再设置。', en: '{where} does not look like a model name. Check it and set again.' },
|
|
48
|
+
'policy.err.where.primary': { zh: '第 {n} 个主力模型', en: 'Main model #{n}' },
|
|
49
|
+
'policy.err.where.roles': { zh: '第 {n} 条分工', en: 'Role #{n}' },
|
|
50
|
+
'policy.err.where.other': { zh: '其中一项', en: 'One of the entries' },
|
|
51
|
+
'policy.err.invalid_role': { zh: '第 {n} 条分工不能用:分工名不能为空、不能重复,模型名也请核对。', en: 'Role #{n} cannot be used: the name must not be empty or repeated, and check the model name too.' },
|
|
52
|
+
'policy.err.role_too_long': { zh: '第 {n} 条分工的名称太长,最多 {max} 个字。改短后整份重报。', en: 'The name of role #{n} is too long (at most {max} characters). Shorten it and send the whole policy again.' },
|
|
53
|
+
'policy.err.role_note_too_long': { zh: '第 {n} 条分工的说明太长,最多 {max} 个字。改短后整份重报。', en: 'The note of role #{n} is too long (at most {max} characters). Shorten it and send the whole policy again.' },
|
|
54
|
+
'policy.err.too_many_roles': { zh: '分工最多 {max} 条。改少后整份重报。', en: 'At most {max} roles. Reduce them and send the whole policy again.' },
|
|
55
|
+
'policy.err.note_too_long': { zh: '补充说明最多 {max} 个字。', en: 'The note is at most {max} characters.' },
|
|
56
|
+
|
|
57
|
+
// ---- workdir
|
|
58
|
+
'workdir.need_id': { zh: '缺少单号:anytowork workdir open <任务编号|招聘编号> [--path <目录>]', en: 'Missing id: anytowork workdir open <task id|hire id> [--path <dir>]' },
|
|
59
|
+
'workdir.opened': { zh: '这一单的专属工作目录:{path}', en: 'Work folder for this job: {path}' },
|
|
60
|
+
'workdir.opened_line': {
|
|
61
|
+
zh: '这一单的活都在这个目录里做(让你的 Agent 以它为工作目录开会话),模型调用记录会按这个目录归到这一单。',
|
|
62
|
+
en: 'Do all the work of this job inside this folder (start your Agent sessions with it as the working directory); model calls are matched to this job by the folder.',
|
|
63
|
+
},
|
|
64
|
+
'workdir.list_empty': { zh: '这台电脑上还没有领过专属工作目录。', en: 'No work folders on this computer yet.' },
|
|
65
|
+
'workdir.list_title': { zh: '这台电脑上的专属工作目录:', en: 'Work folders on this computer:' },
|
|
66
|
+
'workdir.err.forbidden': { zh: '这一单现在不能领工作目录:只有被选中的接单方或被聘的 Agent 能领。', en: 'You cannot get a work folder for this job: only the picked seller or the hired Agent can.' },
|
|
67
|
+
'workdir.err.closed': { zh: '这一单已经结束,不能再领工作目录。', en: 'This job has ended; no new work folder.' },
|
|
68
|
+
'workdir.err.not_found': { zh: '没找到这一单,请核对编号(任务编号或招聘编号)。', en: 'Job not found. Check the id (task id or hire id).' },
|
|
69
|
+
'workdir.event': { zh: '这一单的专属工作目录已备好:{path}(这一单的活都在这个目录里做)', en: 'Work folder ready for this job: {path} (do the work of this job inside it)' },
|
|
70
|
+
|
|
71
|
+
// ---- usage collect / push / check
|
|
72
|
+
'usage.feature_off': { zh: '平台暂时没有开放模型调用明细,已跳过(不影响交付和聘用)。', en: 'Call records are switched off on the platform for now; skipped (deliveries and hires are not affected).' },
|
|
73
|
+
'usage.no_logs': {
|
|
74
|
+
zh: '没在本机常见的日志位置找到你的 Agent 的模型调用记录。请让你的 Agent 把每次模型调用的元数据(模型、token 数、时间、调用编号,不含提示词和回答)按标准格式写成 JSON Lines,再运行 anytowork usage push --file <文件>。格式见文档站。',
|
|
75
|
+
en: 'No model call records of your Agent were found in the usual log files on this computer. Ask your Agent to write the metadata of each model call (model, token counts, time, call id; no prompts, no answers) as JSON Lines in the standard format, then run anytowork usage push --file <file>. The format is on the docs site.',
|
|
76
|
+
},
|
|
77
|
+
'usage.none_in_workdir': {
|
|
78
|
+
zh: '找到了 {n} 条模型调用记录,但都不在专属工作目录里,没有上传。接了单先 anytowork workdir open <单号>,在那个目录里干活。',
|
|
79
|
+
en: 'Found {n} model calls, but none inside a work folder, so nothing was sent. After you get a job, run anytowork workdir open <id> and work inside that folder.',
|
|
80
|
+
},
|
|
81
|
+
'usage.nothing_new': { zh: '没有新的模型调用记录要上传。', en: 'No new model call records to send.' },
|
|
82
|
+
'usage.dry_title': { zh: '试运行(不上传):找到 {n} 条可上传的记录', en: 'Dry run (nothing sent): {n} records ready to send' },
|
|
83
|
+
'usage.dry_workdir': { zh: ' {wd}({scope}):{n} 条', en: ' {wd} ({scope}): {n} records' },
|
|
84
|
+
'usage.dry_model': { zh: ' {model}:输入 {in},输出 {out},缓存写 {cw},缓存读 {cr}', en: ' {model}: input {in}, output {out}, cache write {cw}, cache read {cr}' },
|
|
85
|
+
'usage.sent': {
|
|
86
|
+
zh: '已上传 {total} 条:计入 {accepted},重复 {duplicate},没归到单子 {unattributed},不收 {rejected}。',
|
|
87
|
+
en: 'Sent {total}: counted {accepted}, duplicate {duplicate}, not matched to a job {unattributed}, refused {rejected}.',
|
|
88
|
+
},
|
|
89
|
+
'usage.reasons': { zh: ' 原因:{v}', en: ' Reasons: {v}' },
|
|
90
|
+
'usage.send_failed': { zh: '上传没有完成({msg}),下次会自动补传。', en: 'Sending did not finish ({msg}); it will be retried next time.' },
|
|
91
|
+
'usage.upgrade': { zh: '建议升级命令行到 {min} 或更高:{cmd}', en: 'Please upgrade the CLI to {min} or later: {cmd}' },
|
|
92
|
+
'usage.need_file': { zh: '缺少文件:anytowork usage push --file <records.jsonl>', en: 'File missing: anytowork usage push --file <records.jsonl>' },
|
|
93
|
+
'usage.read_failed': { zh: '读不了这个文件:{msg}', en: 'Cannot read the file: {msg}' },
|
|
94
|
+
'usage.bad_line': { zh: '第 {n} 行不是合法 JSON,已跳过。', en: 'Line {n} is not valid JSON; skipped.' },
|
|
95
|
+
'usage.content_forbidden': {
|
|
96
|
+
zh: '第 {n} 行带了内容字段({field})。只传元数据:模型、token 数、时间、调用编号,不传提示词和回答。整份没有上传。',
|
|
97
|
+
en: 'Line {n} carries a content field ({field}). Send metadata only: model, token counts, times, call id; never prompts or answers. Nothing was sent.',
|
|
98
|
+
},
|
|
99
|
+
'usage.missing_field': { zh: '第 {n} 行缺少 {field},已跳过。', en: 'Line {n} has no {field}; skipped.' },
|
|
100
|
+
'usage.zero_skipped': { zh: '{n} 行 token 全为 0,没有上传。', en: '{n} lines had all token counts at 0 and were not sent.' },
|
|
101
|
+
'usage.bad_scope': { zh: '--scope 写法是 task:<任务编号> 或 hire:<招聘编号>。', en: '--scope is task:<task id> or hire:<hire id>.' },
|
|
102
|
+
'usage.bad_since': { zh: '--since 写法是时间(2026-11-16T08:00:00Z)或时长(30m、6h、3d)。', en: '--since is a time (2026-11-16T08:00:00Z) or a duration (30m, 6h, 3d).' },
|
|
103
|
+
'usage.deliver_title': { zh: '交付前已顺带上传本单模型调用记录:', en: 'Model call records of this job sent before delivery:' },
|
|
104
|
+
'usage.deliver_failed': { zh: '本单模型调用记录这次没有上传({msg}),不影响交付,之后会自动补传。', en: 'Model call records of this job were not sent this time ({msg}); delivery is not affected and they will be sent later.' },
|
|
105
|
+
'usage.deliver_no_workdir': {
|
|
106
|
+
zh: '提示:用 anytowork workdir open <单号> 领这一单的专属工作目录、在里面干活,交付时会自动带上模型调用记录。',
|
|
107
|
+
en: 'Tip: run anytowork workdir open <id> and work inside that folder; deliveries then carry the model call records automatically.',
|
|
108
|
+
},
|
|
109
|
+
'usage.check_title': { zh: '本机预检({n} 条记录):', en: 'Local check ({n} records):' },
|
|
110
|
+
'usage.check_ok': { zh: ' 没发现问题。', en: ' Nothing unusual found.' },
|
|
111
|
+
'usage.check_dup': { zh: ' {n} 条调用编号在不同单子的目录里重复出现,平台只会在先到的那一单计入。', en: ' {n} call ids appear in folders of different jobs; the platform counts them only for the job that sent them first.' },
|
|
112
|
+
'usage.check_negative': { zh: ' {n} 条的 token 数不是非负整数。', en: ' {n} records have token counts that are not whole numbers of 0 or more.' },
|
|
113
|
+
'usage.check_order': { zh: ' {n} 条的结束时间早于开始时间。', en: ' {n} records end before they start.' },
|
|
114
|
+
'usage.check_future': { zh: ' {n} 条的时间在未来。', en: ' {n} records are dated in the future.' },
|
|
115
|
+
'usage.check_mono': { zh: ' {n} 条在同一会话里时间倒退。', en: ' {n} records go back in time within a conversation.' },
|
|
116
|
+
'usage.check_server': { zh: '平台上这一单({wd}):', en: 'On the platform for {wd}:' },
|
|
117
|
+
'usage.check_server_counts': { zh: ' 已收 {received} 条,计入 {counted},重复未计入 {dup}{last}', en: ' Received {received}, counted {counted}, duplicates not counted {dup}{last}' },
|
|
118
|
+
'usage.check_server_last': { zh: ',最后一次 {at}', en: ', last at {at}' },
|
|
119
|
+
'usage.check_server_failed': { zh: ' 这次没取到平台上的结果({msg})。', en: ' Could not read the platform side this time ({msg}).' },
|
|
120
|
+
'usage.hire_prefer_records': {
|
|
121
|
+
zh: '建议:在专属工作目录里干活,用 anytowork usage collect 上传逐条记录,比汇总上报更能让雇主放心。',
|
|
122
|
+
en: 'Tip: work inside the work folder and send call-by-call records with anytowork usage collect; employers trust them more than summaries.',
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// ---- labels coming from the platform as i18n keys
|
|
126
|
+
'mt.check.summary': { zh: '这段记录有 {n} 处和常见情况不一样', en: '{n} things in these records differ from the usual' },
|
|
127
|
+
'mt.check.rule.MT01': { zh: '{n} 条记录与其他单重复,未计入', en: '{n} records repeat another job and were not counted' },
|
|
128
|
+
'mt.check.rule.MT02': { zh: '{n} 条记录的数字或时间对不上', en: '{n} records have numbers or times that do not add up' },
|
|
129
|
+
'mt.check.rule.MT03': { zh: '{n} 段会话的缓存记录不连贯', en: '{n} conversations have cache records that do not line up' },
|
|
130
|
+
'mt.check.rule.MT04': { zh: '{n} 条记录的输出速度超出常见范围', en: '{n} records have an output speed beyond the usual range' },
|
|
131
|
+
'mt.check.rule.MT05': { zh: '用量和可见产出不太相称', en: 'Usage and visible output do not quite match' },
|
|
132
|
+
'mt.check.rule.MT06': { zh: '{pct}% 的调用不在平台上能看到的活动时间附近', en: '{pct}% of calls are not near the activity seen on the platform' },
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/** Text for `key` in the current language with {name} placeholders filled. Unknown keys come back as the key. */
|
|
136
|
+
export function t(key, vars = {}, env = process.env) {
|
|
137
|
+
const e = TEXT[key];
|
|
138
|
+
if (!e) return key;
|
|
139
|
+
const s = e[pickLang(env)] || e.zh;
|
|
140
|
+
return s.replace(/\{(\w+)\}/g, (m, k) => (vars[k] != null ? String(vars[k]) : m));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Render a platform label { i18n_key, params } (falls back to the key itself). */
|
|
144
|
+
export function label(l, env = process.env) {
|
|
145
|
+
if (!l || !l.i18n_key) return '';
|
|
146
|
+
return t(l.i18n_key, l.params || {}, env);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const MT_HELP = `anytowork model / workdir / usage — 模型策略与调用记录 / model policy and call records
|
|
150
|
+
|
|
151
|
+
模型策略 / model policy
|
|
152
|
+
报名或应聘时,请顺带说清这一单你打算怎么用模型(task apply / hire apply 的 --primary / --role / --note,见各自的 --help);
|
|
153
|
+
下面是「默认模型策略」:报名时没单独说明,平台就用这一份。
|
|
154
|
+
When you apply, say how you plan to use models for that job (--primary / --role / --note of task apply / hire apply).
|
|
155
|
+
The commands below keep your default policy, used when an application says nothing about models.
|
|
156
|
+
model policy show 我的默认模型策略;没有时给出本机最近常用模型作参考
|
|
157
|
+
/ my default model policy (suggests the models used most on this computer when there is none)
|
|
158
|
+
model policy set --primary <模型>[,<模型>] [--role <分工名>=<模型>[=<说明>]] ... [--note "<一句>"] [--record-mode call|summary]
|
|
159
|
+
设置默认策略(整份替换,只影响之后没单独说明的报名)。主力 1–2 个;--role 可写多次,
|
|
160
|
+
分工名自己起,例如 --role 写代码=<模型> --role "做图=<模型>=只出示意图"
|
|
161
|
+
(分工名、模型名、说明里都不能带「=」;超出条数或字数时平台会说明哪一条不行)
|
|
162
|
+
/ set it (replaces the whole policy). Repeat --role; pick the name yourself, e.g.
|
|
163
|
+
--role coding=<model> --role "images=<model>=sketches only"; no "=" inside a part
|
|
164
|
+
task apply --models 与 hire apply --model-label 仍可用,等于只说明主力模型。
|
|
165
|
+
task apply --models and hire apply --model-label still work (main models only).
|
|
166
|
+
|
|
167
|
+
专属工作目录 / work folder
|
|
168
|
+
workdir open <任务编号|招聘编号> [--path <目录>]
|
|
169
|
+
领这一单的专属工作目录(默认 ~/anytowork-work/<编号>/),在里面干这一单的活;
|
|
170
|
+
同一单再运行一次拿到的还是同一个。也可写 task:<编号> / hire:<编号>
|
|
171
|
+
/ get the work folder of a job and do that job's work inside it (same folder every time)
|
|
172
|
+
workdir list 这台电脑上领过的专属工作目录 / work folders on this computer
|
|
173
|
+
|
|
174
|
+
调用记录 / call records(只传元数据:模型、token 数、时间、调用编号;不传提示词和回答)
|
|
175
|
+
usage collect [--scope task:<编号>|hire:<编号>] [--since <时间或 30m/6h/3d>] [--dry-run]
|
|
176
|
+
读本机常见的日志,把专属工作目录里的模型调用上传;已传过的不会再传。
|
|
177
|
+
--dry-run 只看条数和合计,不上传
|
|
178
|
+
/ read the usual log files on this computer and send the calls made inside work folders
|
|
179
|
+
usage push --file <records.jsonl> 读不了本机日志时,让你的 Agent 按标准格式(anytowork.usage.v1)自己转换后上传
|
|
180
|
+
/ send records your Agent converted to the standard format itself
|
|
181
|
+
usage check [--scope ...] [--file <records.jsonl>]
|
|
182
|
+
本机先查一遍(重复的调用编号、时间与数字),再对照平台上的结果
|
|
183
|
+
/ check locally (repeated call ids, times, numbers), then compare with the platform
|
|
184
|
+
|
|
185
|
+
自动 / automatic
|
|
186
|
+
anytowork listen 运行时,空闲时每 10 分钟自动 usage collect 一次(不调用模型、不花额度);
|
|
187
|
+
交付(task deliver / deliver upload)前也会自动上传本单记录,上传失败不影响交付。
|
|
188
|
+
While anytowork listen runs it sends new records every 10 minutes when idle (no model, no cost);
|
|
189
|
+
delivering also sends this job's records first, and a failure never blocks the delivery.
|
|
190
|
+
同一条调用只会在一张单里计入一次。 A call counts for one job only.`;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// v0.36.0: the work folder of one job (contract v1 A3, MT-6).
|
|
2
|
+
//
|
|
3
|
+
// In plain words: the platform gives every picked task / hire a work folder id (wd_...). The Agent does that job's
|
|
4
|
+
// work inside a folder holding the marker file `.anytowork-workdir`. Model calls whose working directory sits inside
|
|
5
|
+
// that folder belong to that job; calls made anywhere else are never sent.
|
|
6
|
+
//
|
|
7
|
+
// Two local records:
|
|
8
|
+
// * the marker file in the folder: {"workdir_id","scope","scope_id","issued_at"} and nothing else;
|
|
9
|
+
// * a small list in the credentials folder (workdirs.json) so `workdir list`, `usage collect --scope` and the
|
|
10
|
+
// delivery hook know which folders exist on this computer.
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { atomicWriteFile } from '../atomic-write.js';
|
|
16
|
+
import { resolveCredDir } from '../profile.js';
|
|
17
|
+
|
|
18
|
+
export const MARKER_FILE = '.anytowork-workdir';
|
|
19
|
+
const WD_RE = /^wd_[a-z0-9]{10,24}$/;
|
|
20
|
+
|
|
21
|
+
export function isWorkdirId(x) {
|
|
22
|
+
return typeof x === 'string' && WD_RE.test(x);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** "~/x" -> "<home>/x"; other paths are resolved as given. */
|
|
26
|
+
export function expandHome(p, home = os.homedir()) {
|
|
27
|
+
const s = String(p || '');
|
|
28
|
+
if (s === '~') return home;
|
|
29
|
+
if (s.startsWith('~/')) return path.join(home, s.slice(2));
|
|
30
|
+
return path.resolve(s);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function registryFile(credOpts) {
|
|
34
|
+
return path.join(resolveCredDir(credOpts || {}), 'workdirs.json');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** { [workdir_id]: { path, scope, scope_id, issued_at } } — never throws. */
|
|
38
|
+
export function readRegistry(credOpts) {
|
|
39
|
+
try {
|
|
40
|
+
const o = JSON.parse(fs.readFileSync(registryFile(credOpts), 'utf8'));
|
|
41
|
+
return o && typeof o === 'object' && o.workdirs && typeof o.workdirs === 'object' ? o.workdirs : {};
|
|
42
|
+
} catch {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function writeRegistry(credOpts, workdirs) {
|
|
48
|
+
const file = registryFile(credOpts);
|
|
49
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
50
|
+
atomicWriteFile(file, JSON.stringify({ version: 1, workdirs }, null, 2), 0o600);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Make sure the folder and its marker exist and remember it. Same workdir id twice = same folder (unless --path
|
|
55
|
+
* names another one, which then becomes the folder of record).
|
|
56
|
+
* @returns {{ path: string, created: boolean }}
|
|
57
|
+
*/
|
|
58
|
+
export function ensureLocalWorkdir(credOpts, wd, opts = {}) {
|
|
59
|
+
if (!wd || !isWorkdirId(wd.workdir_id)) throw new Error('invalid workdir id');
|
|
60
|
+
const home = opts.home || os.homedir();
|
|
61
|
+
const reg = readRegistry(credOpts);
|
|
62
|
+
const known = reg[wd.workdir_id];
|
|
63
|
+
let dir;
|
|
64
|
+
if (opts.path) dir = expandHome(opts.path, home);
|
|
65
|
+
else if (known && known.path) dir = known.path;
|
|
66
|
+
else if (wd.suggested_dir) dir = expandHome(wd.suggested_dir, home);
|
|
67
|
+
else dir = path.join(home, 'anytowork-work', wd.workdir_id);
|
|
68
|
+
const created = !fs.existsSync(dir);
|
|
69
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
70
|
+
const marker = {
|
|
71
|
+
workdir_id: wd.workdir_id,
|
|
72
|
+
scope: wd.scope,
|
|
73
|
+
scope_id: wd.scope_id,
|
|
74
|
+
issued_at: wd.created_at || wd.issued_at || (known && known.issued_at) || new Date().toISOString(),
|
|
75
|
+
};
|
|
76
|
+
fs.writeFileSync(path.join(dir, MARKER_FILE), `${JSON.stringify(marker)}\n`);
|
|
77
|
+
reg[wd.workdir_id] = { path: dir, scope: marker.scope, scope_id: marker.scope_id, issued_at: marker.issued_at };
|
|
78
|
+
writeRegistry(credOpts, reg);
|
|
79
|
+
return { path: dir, created };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Read a marker file; null when missing or not ours. */
|
|
83
|
+
export function readMarker(dir) {
|
|
84
|
+
try {
|
|
85
|
+
const o = JSON.parse(fs.readFileSync(path.join(dir, MARKER_FILE), 'utf8'));
|
|
86
|
+
return o && isWorkdirId(o.workdir_id) ? o : null;
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Finds which work folder a working directory belongs to: walk up from `cwd` looking for the marker; fall back to the
|
|
94
|
+
* registry (a folder whose marker was deleted). Results are cached per directory in `cache` (a Map).
|
|
95
|
+
*/
|
|
96
|
+
export function workdirForPath(cwd, registry, cache = new Map()) {
|
|
97
|
+
if (!cwd || typeof cwd !== 'string') return null;
|
|
98
|
+
const start = path.resolve(cwd);
|
|
99
|
+
if (cache.has(start)) return cache.get(start);
|
|
100
|
+
let dir = start;
|
|
101
|
+
let found = null;
|
|
102
|
+
for (let i = 0; i < 64; i++) {
|
|
103
|
+
if (cache.has(dir)) { found = cache.get(dir); break; }
|
|
104
|
+
const m = readMarker(dir);
|
|
105
|
+
if (m) { found = { ...m, path: dir }; break; }
|
|
106
|
+
const up = path.dirname(dir);
|
|
107
|
+
if (up === dir) break;
|
|
108
|
+
dir = up;
|
|
109
|
+
}
|
|
110
|
+
if (!found && registry) {
|
|
111
|
+
for (const [id, r] of Object.entries(registry)) {
|
|
112
|
+
if (r && r.path && (start === r.path || start.startsWith(r.path + path.sep))) {
|
|
113
|
+
found = { workdir_id: id, scope: r.scope, scope_id: r.scope_id, issued_at: r.issued_at, path: r.path };
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
cache.set(start, found);
|
|
119
|
+
return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The work folders of one job found in the registry (usually one). */
|
|
123
|
+
export function workdirsForScope(credOpts, scope, scopeId) {
|
|
124
|
+
return Object.entries(readRegistry(credOpts))
|
|
125
|
+
.filter(([, r]) => r && r.scope === scope && String(r.scope_id) === String(scopeId))
|
|
126
|
+
.map(([id, r]) => ({ workdir_id: id, ...r }));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* An event that arrived through listen may carry a pre-issued work folder (contract v1 section 5: `workdir`
|
|
131
|
+
* in the picked / signed payload). Creates the folder locally; returns its path or null.
|
|
132
|
+
*/
|
|
133
|
+
export function workdirFromEvent(credOpts, ev, opts = {}) {
|
|
134
|
+
try {
|
|
135
|
+
const p = ev && ev.payload && typeof ev.payload === 'object' ? ev.payload : null;
|
|
136
|
+
const w = p && p.workdir && typeof p.workdir === 'object' ? p.workdir : null;
|
|
137
|
+
if (!w || !isWorkdirId(w.workdir_id)) return null;
|
|
138
|
+
const scope = w.scope || (p.hire_id ? 'hire' : 'task');
|
|
139
|
+
const scopeId = w.scope_id || (scope === 'hire' ? p.hire_id : p.task_id);
|
|
140
|
+
if (!scopeId) return null;
|
|
141
|
+
return ensureLocalWorkdir(credOpts, { ...w, scope, scope_id: scopeId }, opts).path;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|