@rfany/rf 0.9.0 → 0.10.0
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/rf.mjs +55 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfany/rf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "rollforward's command line for people: what its page does, from a shell or a desktop agent, as you",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": { "type": "git", "url": "git+https://github.com/spoj/rollforward.git", "directory": "cli" },
|
package/rf.mjs
CHANGED
|
@@ -8,9 +8,10 @@ import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
|
8
8
|
|
|
9
9
|
const USAGE = `rf login URL [TOKEN] without a TOKEN, through the browser: allow it on the page, where it shows rf's code
|
|
10
10
|
rf ls
|
|
11
|
-
rf pull PATH DIR [--delete] [-n|--dry-run] [--exclude PATTERN]...
|
|
11
|
+
rf pull PATH DIR [--delete] [-n|--dry-run] [--exclude PATTERN]... [--max-size SIZE]
|
|
12
12
|
PATH's files into DIR as rsync copies them, whole, if their size or time differ: PATH/ fills DIR,
|
|
13
|
-
PATH makes DIR/<its name>, / is all you see; --delete removes what the server no longer has
|
|
13
|
+
PATH makes DIR/<its name>, / is all you see; --delete removes what the server no longer has;
|
|
14
|
+
--max-size skips files bigger than SIZE, such as 50M
|
|
14
15
|
rf help how rollforward works and how to use rf, for an agent
|
|
15
16
|
rf comment PATH TEXT [--item ID] [--ref REF] [--thread T] [--wait] a new thread, or a reply in T, as to an agent's ask
|
|
16
17
|
rf upload PATH FILE [--onto ITEM] [--output]
|
|
@@ -27,8 +28,14 @@ rf status [--long MIN] [--json] what goes on and what's stuck: runs going, fla
|
|
|
27
28
|
rf indexes [--json] each index of a source you index, all for admins: its kind, items and size, and per person
|
|
28
29
|
its phase, crawl or follow, pages read, when last caught up, and its error and next try
|
|
29
30
|
rf runs [PATH] [--since DATE] [--failed] [--running] [--long MIN] [--json]
|
|
30
|
-
a line per run: start, path, run, outcome, time, cost, what started it, summary or error
|
|
31
|
-
|
|
31
|
+
a line per run: start, path, run, outcome, time, cost, what started it, summary or error;
|
|
32
|
+
the outcome is done, interrupted by a person, cut by a restart, running, or failed, for
|
|
33
|
+
credits, policy, time limit or other
|
|
34
|
+
rf costs [PATH] [--since DATE] [--by workspace|series|person|day|outcome] [--json] totals, runs and cost per run; person
|
|
35
|
+
is the runner; runs leave out those a restart cut, as the next run carries each on
|
|
36
|
+
rf activity [PATH] [--since DATE] [--json] per instance, what people said, uploaded and closed, and each run's report
|
|
37
|
+
rf wakes [PATH] [--json] each series' pending wakes and requests to start an instance, and when a wake of it last
|
|
38
|
+
fired, and each instance's pending wakes
|
|
32
39
|
rf people WORKSPACE [--set FILE|-] [-n] [--force] its owners and admins: its people as lines of owner|member EMAIL-OR-GROUP,
|
|
33
40
|
each with a comment; --set replaces them, -n shows the changes, --force hides open instances
|
|
34
41
|
from their runners
|
|
@@ -190,11 +197,14 @@ const excluded = (rel ) => globs.some(([whole, re]) => rel.split('/').som
|
|
|
190
197
|
// fetched, and given the server's time, so the next pull compares against it. Nothing is kept besides the files.
|
|
191
198
|
async function pull(path , dir ) {
|
|
192
199
|
const at = path.replace(/^\/+/, ''), from = at.replace(/\/+$/, ''), dry = !!flags['dry-run'];
|
|
200
|
+
const size = /^(\d+)([KMG]?)$/i.exec(String(flags['max-size'] ?? '0'));
|
|
201
|
+
if (!size) throw new Error(`--max-size: a size such as 500K, 50M or 2G, not ${flags['max-size']}`);
|
|
202
|
+
const max = flags['max-size'] === undefined ? Infinity : Number(size[1]) * 1024 ** ' KMG'.indexOf(size[2].toUpperCase() || ' ');
|
|
193
203
|
const list = await get(`/api/files?path=${encodeURIComponent(from)}`);
|
|
194
204
|
if (!list.length) throw new Error(`nothing you can see at ${path}`);
|
|
195
205
|
const into = !from || at.endsWith('/') ? resolve(dir) : under(resolve(dir), from.slice(from.lastIndexOf('/') + 1)), rel = (f ) => f.path.slice(from ? from.length + 1 : 0);
|
|
196
206
|
if (!into) throw new Error(`${from} can't be a name here: pull ${from}/ into a folder of your choosing`);
|
|
197
|
-
let fetched = 0, same = 0, deleted = 0, failed = 0;
|
|
207
|
+
let fetched = 0, same = 0, deleted = 0, failed = 0, big = 0;
|
|
198
208
|
for (const f of list.filter(f => !excluded(rel(f)))) {
|
|
199
209
|
const local = rel(f) ? under(into, rel(f)) : into, st = local && existsSync(local) ? statSync(local) : undefined;
|
|
200
210
|
if (!local) {
|
|
@@ -205,6 +215,11 @@ async function pull(path , dir ) {
|
|
|
205
215
|
same++;
|
|
206
216
|
continue;
|
|
207
217
|
}
|
|
218
|
+
if (f.size > max) {
|
|
219
|
+
console.log(`skipped ${f.path}: ${f.size} bytes, over --max-size`);
|
|
220
|
+
big++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
208
223
|
console.log(`${st ? 'changed' : 'new'} ${f.path}`);
|
|
209
224
|
try {
|
|
210
225
|
if (!dry) write(local, f.text ?? new Uint8Array(await (await api(f.url )).arrayBuffer()), f.mtime);
|
|
@@ -226,7 +241,7 @@ async function pull(path , dir ) {
|
|
|
226
241
|
const prune = (d ) => { for (const e of readdirSync(d, { withFileTypes: true })) if (e.isDirectory()) prune(join(d, e.name)); if (d !== into && !readdirSync(d).length) rmdirSync(d); };
|
|
227
242
|
if (!dry) prune(into);
|
|
228
243
|
}
|
|
229
|
-
console.log(`${dry ? 'would fetch' : 'fetched'} ${fetched}, ${same} up to date${flags.delete ? `, ${dry ? 'would delete' : 'deleted'} ${deleted}` : ''}${failed ? `, ${failed} failed` : ''}, in ${into}`);
|
|
244
|
+
console.log(`${dry ? 'would fetch' : 'fetched'} ${fetched}, ${same} up to date${big ? `, ${big} over ${flags['max-size']}` : ''}${flags.delete ? `, ${dry ? 'would delete' : 'deleted'} ${deleted}` : ''}${failed ? `, ${failed} failed` : ''}, in ${into}`);
|
|
230
245
|
if (failed) process.exitCode = 1;
|
|
231
246
|
}
|
|
232
247
|
|
|
@@ -337,9 +352,10 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
337
352
|
[`Running`, s.running.map(r => `${r.path} run ${r.run} for ${took((Date.now() - Date.parse(r.at)) / 1000)} ${usd(r.cost)}${Date.now() - Date.parse(r.at) > long * 60e3 ? ` LONG, past ${long}m` : ''}`)],
|
|
338
353
|
[`Queued`, s.queued.map(q => `${q.path} since ${when(q.since)}: ${q.why}`)],
|
|
339
354
|
[`Waiting`, [
|
|
340
|
-
...s.asks
|
|
355
|
+
...[...s.asks, ...s.requests.map(r => ({ ...r, who: r.who ?? 'anyone', since: r.at, text: `${r.from} asks to start ${r.label}`, request: true })),
|
|
356
|
+
...s.proposals.map(p => ({ who: `${p.to}'s owners`, path: p.to, since: p.at, text: `${p.by} proposes to ${p.kind === 'merge' ? `merge ${p.from} into it` : `move ${p.from}/${p.series} to it`}`, proposal: true }))]
|
|
357
|
+
.sort((a, b) => a.who.localeCompare(b.who) || a.since.localeCompare(b.since)).map(a => `${a.who} ${a.proposal ? 'a proposal' : a.request ? 'a request' : a.signoff ? 'a sign-off' : a.note ? 'a note' : 'an ask'} in ${a.path} since ${when(a.since)}: ${a.text.split('\n')[0].slice(0, 80)}`),
|
|
341
358
|
...s.expired.map(e => `${e.who} their ${e.login} login expired${e.holding.length ? `, holding ${e.holding.join(', ')}` : ''}`),
|
|
342
|
-
...s.requests.map(r => `${r.path} ${r.from} asks to start ${r.label}, since ${when(r.at)}`),
|
|
343
359
|
]],
|
|
344
360
|
[`Last run failed`, s.failed.map(f => `${f.path} run ${f.run} at ${when(f.at)}: ${f.error}`)],
|
|
345
361
|
[`Indexes crawling or failing`, ix.filter(x => x.people.some(p => p.phase === 'crawl' || p.error)).map(x => `${x.name} ${x.people.filter(p => p.phase === 'crawl' || p.error)
|
|
@@ -355,18 +371,42 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
355
371
|
} else if (cmd === 'runs' && args.length <= 1) {
|
|
356
372
|
const rows = (await runsIn(args[0])).filter(r => (!flags.failed || r.outcome === 'failed') && (!flags.running || r.outcome === 'running') && (!flags.long || r.seconds >= Number(flags.long) * 60));
|
|
357
373
|
if (flags.json) console.log(JSON.stringify(rows, null, 1));
|
|
358
|
-
else for (const r of rows) console.log(`${when(r.at)} ${r.path} run ${r.run} ${r.outcome} ${took(r.seconds)} ${usd(r.cost)} ${r.started ? `${r.started.op} by ${r.started.by}` : '-'} ${r.error ?? r.summary ?? ''}`);
|
|
374
|
+
else for (const r of rows) console.log(`${when(r.at)} ${r.path} run ${r.run} ${r.outcome}${r.failure ? ` (${r.failure})` : ''} ${took(r.seconds)} ${usd(r.cost)} ${r.started ? `${r.started.op} by ${r.started.by}` : '-'} ${r.error ?? r.summary ?? ''}`);
|
|
359
375
|
} else if (cmd === 'costs' && args.length <= 1) {
|
|
360
|
-
const by = String(flags.by ?? 'series'), key = {
|
|
376
|
+
const by = String(flags.by ?? 'series'), key = {
|
|
377
|
+
workspace: r => r.path.split('/')[0], series: r => r.path.split('/').slice(0, 2).join('/'), person: r => r.runner, day: r => when(r.at).slice(0, 10),
|
|
378
|
+
outcome: r => r.failure ? `failed, ${r.failure}` : r.outcome,
|
|
379
|
+
}[by];
|
|
361
380
|
if (!key) throw new Error(USAGE);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const
|
|
381
|
+
// A run a restart cut is carried on by the next, so it adds its cost, not a run.
|
|
382
|
+
const sums = new Map (), rows = await runsIn(args[0]), counted = (r ) => r.outcome === 'cut' ? 0 : 1;
|
|
383
|
+
for (const r of rows) sums.set(key(r), { runs: (sums.get(key(r))?.runs ?? 0) + counted(r), cost: (sums.get(key(r))?.cost ?? 0) + r.cost });
|
|
384
|
+
const out = [...sums].map(([k, v]) => ({ [by]: k, runs: v.runs, cost: +v.cost.toFixed(4), per_run: v.runs ? +(v.cost / v.runs).toFixed(4) : null }))
|
|
365
385
|
.sort((a, b) => by === 'day' ? a.day.localeCompare(b.day) : b.cost - a.cost);
|
|
366
386
|
if (flags.json) console.log(JSON.stringify(out, null, 1));
|
|
367
387
|
else {
|
|
368
|
-
for (const o of out) console.log(`${usd(o.cost).padStart(10)} ${String(o.runs).padStart(5)} runs ${usd(o.per_run).padStart(8)} a run ${o[by]}`);
|
|
369
|
-
console.log(`${usd(rows.reduce((t, r) => t + r.cost, 0)).padStart(10)} ${String(rows.
|
|
388
|
+
for (const o of out) console.log(`${usd(o.cost).padStart(10)} ${String(o.runs).padStart(5)} runs ${(o.per_run === null ? '-' : usd(o.per_run)).padStart(8)} a run ${o[by]}`);
|
|
389
|
+
console.log(`${usd(rows.reduce((t, r) => t + r.cost, 0)).padStart(10)} ${String(rows.reduce((n, r) => n + counted(r), 0)).padStart(5)} runs in all`);
|
|
390
|
+
}
|
|
391
|
+
} else if (cmd === 'wakes' && args.length <= 1) {
|
|
392
|
+
const at = (args[0] ?? '').replace(/\/+$/, ''), rows = (await get('/api')).flatMap(w => w.series.filter(s => !s.archived).flatMap(s => [
|
|
393
|
+
...(s.single ? [] : [{ path: `${w.name}/${s.name}`, fired: s.fired, wakes: s.wakes, requests: s.requests }]),
|
|
394
|
+
...s.instances.filter(i => i.wakes.length).map(i => ({ path: `${w.name}/${s.name}/${i.label}`, fired: i.fired, wakes: i.wakes, requests: [] })),
|
|
395
|
+
])).filter(r => !at || r.path === at || r.path.startsWith(at + '/'));
|
|
396
|
+
if (flags.json) console.log(JSON.stringify(rows, null, 1));
|
|
397
|
+
else for (const r of rows) {
|
|
398
|
+
console.log(`${r.path} last woken ${r.fired ? when(r.fired) : 'never'}${r.wakes.length || r.requests.length ? '' : ', none pending'}`);
|
|
399
|
+
for (const k of r.wakes) console.log(` wake ${k.id} ${when(k.at)}${k.label ? ` starts ${k.label}` : ''}${k.days ? `, then each ${k.days.join(', ')}` : ''}, set by ${k.from}`);
|
|
400
|
+
for (const q of r.requests) console.log(` request ${q.id} to start ${q.label}, from ${q.from} since ${when(q.at)}, waits on ${q.who ?? 'anyone'}`);
|
|
401
|
+
}
|
|
402
|
+
} else if (cmd === 'activity' && args.length <= 1) {
|
|
403
|
+
const at = (args[0] ?? '').replace(/\/+$/, ''), blocks = (await get(`/api/activity?since=${encodeURIComponent(String(flags.since ?? ''))}`))
|
|
404
|
+
.filter(b => !at || b.path === at || b.path.startsWith(at + '/'));
|
|
405
|
+
if (flags.json) console.log(JSON.stringify(blocks, null, 1));
|
|
406
|
+
else for (const b of blocks) {
|
|
407
|
+
console.log(b.path);
|
|
408
|
+
for (const e of b.entries) console.log(` ${when(e.at)} ${e.op === 'done' ? `run ${e.run} ${e.error ?? e.summary ?? 'no report'}`
|
|
409
|
+
: `${e.by} ${e.op === 'comment' ? `says: ${e.text.split('\n')[0].slice(0, 200)}` : e.op === 'upload' ? `uploads ${e.file}` : `${e.op === 'close' ? 'closes' : 'abandons'} it`}`}`);
|
|
370
410
|
}
|
|
371
411
|
} else if (cmd === 'people' && args.length <= 1) {
|
|
372
412
|
// People as lines to edit and set: ROLE EMAIL for everyone, owner|member EMAIL-OR-GROUP for a workspace, each with a comment.
|