@rfany/rf 0.7.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 +128 -36
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,43 +8,63 @@ 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]
|
|
17
|
-
rf wake PATH AT
|
|
18
|
+
rf wake PATH AT [--label LABEL] [--days DAYS] | rf wake --cancel ID
|
|
19
|
+
AT now, +<n>m|h|d or a date; PATH an open instance, or a series with LABEL; DAYS, such as
|
|
20
|
+
mon-fri, repeats it weekly at AT's time; rf ls shows each wake's ID
|
|
18
21
|
rf agents [WORKSPACE] [--set FILE|-] the company's AGENTS.md, or a workspace's; setting the company's is for admins
|
|
19
22
|
rf skills
|
|
23
|
+
rf skill pull ID [DIR] [--version N] the newest version, or N, into DIR, ./ID by default, new or empty, as push reads it
|
|
24
|
+
rf skill versions ID
|
|
20
25
|
rf connections
|
|
21
26
|
rf status [--long MIN] [--json] what goes on and what's stuck: runs going, flagged past MIN minutes (30), and queued, with why;
|
|
22
27
|
what waits on whom since when; open instances whose last run failed
|
|
28
|
+
rf indexes [--json] each index of a source you index, all for admins: its kind, items and size, and per person
|
|
29
|
+
its phase, crawl or follow, pages read, when last caught up, and its error and next try
|
|
23
30
|
rf runs [PATH] [--since DATE] [--failed] [--running] [--long MIN] [--json]
|
|
24
|
-
a line per run: start, path, run, outcome, time, cost, what started it, summary or error
|
|
25
|
-
|
|
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
|
|
26
39
|
rf people WORKSPACE [--set FILE|-] [-n] [--force] its owners and admins: its people as lines of owner|member EMAIL-OR-GROUP,
|
|
27
40
|
each with a comment; --set replaces them, -n shows the changes, --force hides open instances
|
|
28
41
|
from their runners
|
|
29
42
|
|
|
30
|
-
|
|
43
|
+
Admins, and those they grant publish:
|
|
31
44
|
rf skill push DIR DIR/SKILL.md and the rest become the newest version of the skill named DIR's name, live at once
|
|
32
|
-
rf skill versions ID
|
|
33
45
|
rf skill rollback ID N pushes version N again, as the newest
|
|
34
46
|
|
|
35
47
|
Admins:
|
|
36
48
|
rf people [--set FILE|-] [-n] [--force] everyone as lines of ROLE EMAIL, each with a comment; --set sets the roles of the people
|
|
37
49
|
listed and adds new ones, removing no one
|
|
38
|
-
rf user add EMAIL [admin
|
|
50
|
+
rf user add EMAIL [admin] | role EMAIL admin|user [--force] | disable EMAIL | enable EMAIL | signout EMAIL | remove EMAIL
|
|
39
51
|
rf connection set NAME TYPE [--SETTING VALUE]... an outside system runs reach as their runner, by a login each person makes:
|
|
40
52
|
graph, Microsoft 365, with no settings; databricks, --host HOST --warehouse ID, a workspace
|
|
41
53
|
and its SQL warehouse; website, --url URL [--hosts HOST,...] [--title TITLE] [--writeback
|
|
42
|
-
false]
|
|
43
|
-
|
|
54
|
+
false] [--header NAME] [--keepalive PAGE --every 10m [--hours 08:00-19:00]] [--people
|
|
55
|
+
EMAIL|GROUP,...], where people sign in, the other hosts its pages need, such as
|
|
56
|
+
*.example.com, whether a run's browser writes its state back, a header its sign-in needs
|
|
57
|
+
that its pages never send, such as x-bot-token, whose value each person gives, a page, by
|
|
58
|
+
its address or path, such as https://patriarch.patrina.net/PatriArchMVC/, to load in each
|
|
59
|
+
live login's browser every so often, in office hours on weekdays if given, so idle sessions
|
|
60
|
+
stay alive, and who alone may use it, by email or Entra group id
|
|
44
61
|
rf connection remove NAME
|
|
45
62
|
rf brand [--text TEXT] [--logo FILE] [--clear] the deployment's text and logo, a .png, .jpg, .gif, .webp or .svg, which top
|
|
46
63
|
the sidebar and are the page's title and icon; --clear goes back to the plain look, and with
|
|
47
|
-
no option it prints them
|
|
64
|
+
no option it prints them
|
|
65
|
+
rf can [CAP [EMAIL|GROUP,...] [--clear]] what users may do beyond the rest, as admins may: publish, push skills, and
|
|
66
|
+
create, make workspaces; a list grants CAP to those emails and Entra group ids in place of
|
|
67
|
+
whom it had, --clear to no one, and with neither it prints whom each is granted to`;
|
|
48
68
|
|
|
49
69
|
const GUIDE = `rollforward runs a team's recurring work, such as a weekly borrowing base or a month-end reconciliation, with an agent
|
|
50
70
|
that does each period's work and people who check it. rf does what its page does, as you.
|
|
@@ -64,30 +84,37 @@ What there is
|
|
|
64
84
|
What rf pull copies, the folders as the agent sees them
|
|
65
85
|
AGENTS.md the company's conventions; <workspace>/AGENTS.md the workspace's
|
|
66
86
|
<workspace>/<series>/<label>/
|
|
67
|
-
|
|
87
|
+
screen.json the screen: {rev, status, items: [{id, name, kind, file, from, headline, source}]}
|
|
68
88
|
log.jsonl every event, by seq: by is a person's email, "server" or "agent"; op is upload, comment (thread, item,
|
|
69
89
|
ref, text, ask, to, signoff), resolve, signoff (the runner's answer, with its commit), commit, point and
|
|
70
90
|
item (the screen changing), run, report (the agent's account of a run), done (its cost, summary or
|
|
71
91
|
error), close, and the rest
|
|
72
92
|
upload/ what people uploaded, their comments' attachments in upload/attachments/
|
|
73
93
|
working/ what the agent made, its scripts, and process.md, how it does this series
|
|
74
|
-
session/
|
|
94
|
+
session/ each run's session: every message and tool call of it
|
|
75
95
|
browser/ each run's browser requests, and its screenshots
|
|
96
|
+
skills/ the skills the latest run loaded
|
|
97
|
+
names.tsv each instance in the latest run's reach, id<TAB>/work/<workspace>/<series>/<label>: names can
|
|
98
|
+
change, so where a path in a file doesn't match, look its id up in the names.tsv of the commit
|
|
99
|
+
that last changed the file (git log -1 -- FILE, then git show H:names.tsv), and its name now in
|
|
100
|
+
rf ls
|
|
76
101
|
The copy is read-only, and only rf changes what's on the server: comment, upload and wake.
|
|
77
102
|
|
|
78
103
|
Usual work
|
|
79
104
|
- What waits on me: rf ls, then the asks in that instance's log.jsonl, ask true, whose thread has nothing after them.
|
|
80
105
|
- Answer an ask: rf comment PATH TEXT --thread T --wait, which prints what the agent says back.
|
|
81
106
|
- Give an input or a corrected output: rf upload PATH FILE [--onto ITEM] [--output].
|
|
82
|
-
- Start an instance: rf wake SERIES now
|
|
83
|
-
someone to start it; take one you run up later: rf wake PATH +2h
|
|
107
|
+
- Start an instance: rf wake SERIES now --label LABEL, which starts it as whoever shares the series, else asks on the page for
|
|
108
|
+
someone to start it; take one you run up later: rf wake PATH +2h.
|
|
84
109
|
- Read what a run did: rf pull PATH/ DIR, then its report and done entries in log.jsonl, the files in working/, and session/ for
|
|
85
110
|
every step.
|
|
86
111
|
|
|
87
112
|
Watching over it, for admins and power users; each sees what the caller sees, and takes --json
|
|
88
113
|
- What's stuck: rf status lists runs going, flagging those past --long MIN (30); queued runs, since when and why: their series is
|
|
89
114
|
running, the RF_MAX_RUNS cap, or memory; what waits on whom since when: asks, notes for runners, expired logins and the instances
|
|
90
|
-
they hold, and requests to start;
|
|
115
|
+
they hold, and requests to start; open instances whose last run failed; and indexes crawling or failing.
|
|
116
|
+
- Indexes: rf indexes shows each index of a big library or mailbox you index, every one for admins: its items and size, and per
|
|
117
|
+
person whether it is crawling or following changes, pages read, when last caught up, and an error, if any, with its next try.
|
|
91
118
|
- History: rf runs [PATH] [--since DATE] [--failed] [--running] [--long MIN] prints a line per run: its start, path, run number,
|
|
92
119
|
outcome, time taken, cost, what started it and by whom, and its summary or error. rf costs [PATH] [--since DATE] [--by
|
|
93
120
|
workspace|series|person|day] totals them, by the runner for person.
|
|
@@ -170,11 +197,14 @@ const excluded = (rel ) => globs.some(([whole, re]) => rel.split('/').som
|
|
|
170
197
|
// fetched, and given the server's time, so the next pull compares against it. Nothing is kept besides the files.
|
|
171
198
|
async function pull(path , dir ) {
|
|
172
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() || ' ');
|
|
173
203
|
const list = await get(`/api/files?path=${encodeURIComponent(from)}`);
|
|
174
204
|
if (!list.length) throw new Error(`nothing you can see at ${path}`);
|
|
175
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);
|
|
176
206
|
if (!into) throw new Error(`${from} can't be a name here: pull ${from}/ into a folder of your choosing`);
|
|
177
|
-
let fetched = 0, same = 0, deleted = 0, failed = 0;
|
|
207
|
+
let fetched = 0, same = 0, deleted = 0, failed = 0, big = 0;
|
|
178
208
|
for (const f of list.filter(f => !excluded(rel(f)))) {
|
|
179
209
|
const local = rel(f) ? under(into, rel(f)) : into, st = local && existsSync(local) ? statSync(local) : undefined;
|
|
180
210
|
if (!local) {
|
|
@@ -185,6 +215,11 @@ async function pull(path , dir ) {
|
|
|
185
215
|
same++;
|
|
186
216
|
continue;
|
|
187
217
|
}
|
|
218
|
+
if (f.size > max) {
|
|
219
|
+
console.log(`skipped ${f.path}: ${f.size} bytes, over --max-size`);
|
|
220
|
+
big++;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
188
223
|
console.log(`${st ? 'changed' : 'new'} ${f.path}`);
|
|
189
224
|
try {
|
|
190
225
|
if (!dry) write(local, f.text ?? new Uint8Array(await (await api(f.url )).arrayBuffer()), f.mtime);
|
|
@@ -206,7 +241,7 @@ async function pull(path , dir ) {
|
|
|
206
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); };
|
|
207
242
|
if (!dry) prune(into);
|
|
208
243
|
}
|
|
209
|
-
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}`);
|
|
210
245
|
if (failed) process.exitCode = 1;
|
|
211
246
|
}
|
|
212
247
|
|
|
@@ -231,9 +266,16 @@ if (cmd === 'login' && url) {
|
|
|
231
266
|
writeFileSync(config, JSON.stringify({ url, token }), { mode: 0o600 });
|
|
232
267
|
console.log(`signed in as ${me.email}`);
|
|
233
268
|
} else if (cmd === 'ls') {
|
|
269
|
+
const wakes = (list ) => {
|
|
270
|
+
for (const k of list) console.log(` wake ${k.id} ${k.at}${k.label ? ` starts ${k.label}` : ''}${k.days ? `, then each ${k.days.join(', ')}` : ''}`);
|
|
271
|
+
};
|
|
234
272
|
for (const w of await get('/api')) for (const s of w.series) {
|
|
235
|
-
console.log(`${w.name}/${s.name}${s.
|
|
236
|
-
|
|
273
|
+
console.log(`${w.name}/${s.name}${s.requests.length ? ` ${s.requests.length} asking to start` : ''}`);
|
|
274
|
+
wakes(s.wakes);
|
|
275
|
+
for (const i of s.instances) {
|
|
276
|
+
console.log(`${w.name}/${s.name}/${i.label} ${i.status}${i.running ? ', running' : ''}${i.asks.length ? `, ${i.asks.length} asks waiting` : ''}, runner ${i.runner}`);
|
|
277
|
+
wakes(i.wakes);
|
|
278
|
+
}
|
|
237
279
|
}
|
|
238
280
|
} else if (cmd === 'pull' && args.length === 2) await pull(args[0], args[1]);
|
|
239
281
|
else if (cmd === 'comment' && args.length === 2) {
|
|
@@ -256,11 +298,14 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
256
298
|
const q = new URLSearchParams({ name: basename(args[1]), pane: flags.output ? 'out' : 'in', ...(typeof flags.onto === 'string' && { onto: flags.onto }) });
|
|
257
299
|
await api(`${(await find(args[0])).at}/upload?${q}`, { method: 'POST', body: readFileSync(args[1]) });
|
|
258
300
|
console.log('uploaded');
|
|
259
|
-
} else if (cmd === 'wake' && args.length
|
|
301
|
+
} else if (cmd === 'wake' && typeof flags.cancel === 'string' && !args.length) {
|
|
302
|
+
await api(`/api/wakes/${flags.cancel}`, { method: 'DELETE' });
|
|
303
|
+
console.log('cancelled');
|
|
304
|
+
} else if (cmd === 'wake' && args.length === 2) {
|
|
260
305
|
const { series, inst } = await find(args[0]);
|
|
261
306
|
const at = args[1] === 'now' ? Date.now() : args[1].startsWith('+') ? Date.now() + Number(args[1].slice(1, -1)) * { m: 60e3, h: 3600e3, d: 86400e3 }[args[1].at(-1) ] : Date.parse(args[1]);
|
|
262
|
-
const w = await (await post(`/api/wakes/${inst?.id ?? series.id}`, { at: new Date(at).toISOString(),
|
|
263
|
-
console.log(`
|
|
307
|
+
const w = await (await post(`/api/wakes/${inst?.id ?? series.id}`, { at: new Date(at).toISOString(), label: flags.label, days: flags.days }, 'PUT')).json();
|
|
308
|
+
console.log(`wake ${w.id} at ${w.at}${w.days ? `, then each ${w.days.join(', ')}` : ''}`);
|
|
264
309
|
} else if (cmd === 'agents' && args.length <= 1) {
|
|
265
310
|
const ws = args[0] === undefined ? undefined : (await get('/api')).find(w => w.name === args[0]);
|
|
266
311
|
if (args[0] !== undefined && !ws) throw new Error(`no workspace ${args[0]}`);
|
|
@@ -274,6 +319,17 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
274
319
|
const files = Object.fromEntries(readdirSync(args[1], { recursive: true, withFileTypes: true }).filter(d => d.isFile())
|
|
275
320
|
.map(d => [relative(args[1], join(d.parentPath, d.name)).split(sep).join('/'), readFileSync(join(d.parentPath, d.name)).toString('base64')]));
|
|
276
321
|
console.log(await (await post(`/skills/${encodeURIComponent(basename(resolve(args[1])))}/versions`, { files })).text());
|
|
322
|
+
} else if (cmd === 'skill' && args[0] === 'pull' && args[1] && args.length <= 3) {
|
|
323
|
+
const id = encodeURIComponent(args[1]), dir = resolve(args[2] ?? args[1]), n = flags.version ?? (await get(`/skills/${id}/versions`)).at(-1)?.version;
|
|
324
|
+
if (n === undefined) throw new Error(`no skill ${args[1]}`);
|
|
325
|
+
if (existsSync(dir) && readdirSync(dir).length) throw new Error(`${dir} isn't empty: pull into a new folder, so nothing stale goes along when you push it`);
|
|
326
|
+
for (const [rel, data] of Object.entries (await get(`/skills/${id}/versions/${n}`))) {
|
|
327
|
+
const path = under(dir, rel);
|
|
328
|
+
if (!path) throw new Error(`${rel} can't be a file's name here`);
|
|
329
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
330
|
+
writeFileSync(path, Buffer.from(data, 'base64'));
|
|
331
|
+
}
|
|
332
|
+
console.log(`pulled ${args[1]} version ${n} into ${dir}`);
|
|
277
333
|
} else if (cmd === 'skill' && args[0] === 'versions' && args[1]) {
|
|
278
334
|
for (const v of await get(`/skills/${encodeURIComponent(args[1])}/versions`)) console.log(`${v.version} ${v.at} ${v.by}`);
|
|
279
335
|
} else if (cmd === 'skill' && args[0] === 'rollback' && args.length === 3) {
|
|
@@ -289,36 +345,68 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
289
345
|
await api(`/connections/${encodeURIComponent(args[1])}`, { method: 'DELETE' });
|
|
290
346
|
console.log('removed');
|
|
291
347
|
} else if (cmd === 'status' && !args.length) {
|
|
292
|
-
const s = await get('/api/status'), long = Number(flags.long ?? 30);
|
|
293
|
-
if (flags.json) console.log(JSON.stringify(s, null, 1));
|
|
348
|
+
const [s, ix] = await Promise.all([get('/api/status'), get('/api/indexes')]), long = Number(flags.long ?? 30);
|
|
349
|
+
if (flags.json) console.log(JSON.stringify({ ...s, indexes: ix }, null, 1));
|
|
294
350
|
else {
|
|
295
351
|
const sections = [
|
|
296
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` : ''}`)],
|
|
297
353
|
[`Queued`, s.queued.map(q => `${q.path} since ${when(q.since)}: ${q.why}`)],
|
|
298
354
|
[`Waiting`, [
|
|
299
|
-
...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)}`),
|
|
300
358
|
...s.expired.map(e => `${e.who} their ${e.login} login expired${e.holding.length ? `, holding ${e.holding.join(', ')}` : ''}`),
|
|
301
|
-
...s.requests.map(r => `${r.path} ${r.from} asks to start ${r.label}, since ${when(r.at)}: ${r.reason}`),
|
|
302
359
|
]],
|
|
303
360
|
[`Last run failed`, s.failed.map(f => `${f.path} run ${f.run} at ${when(f.at)}: ${f.error}`)],
|
|
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)
|
|
362
|
+
.map(p => `${p.who} ${p.error ? `failing${p.retry_at ? `, again ${when(p.retry_at)}` : ''}: ${p.error.split('\n')[0].slice(0, 80)}` : `crawling, ${p.pages} pages`}`).join('; ')}`)],
|
|
304
363
|
].filter(([, rows]) => rows.length);
|
|
305
364
|
console.log(sections.map(([title, rows]) => `${title} (${rows.length})\n${rows.map(r => ` ${r}`).join('\n')}`).join('\n\n') || 'Nothing is running, queued, waiting or failed.');
|
|
306
365
|
}
|
|
366
|
+
} else if (cmd === 'indexes' && !args.length) {
|
|
367
|
+
const ix = await get('/api/indexes');
|
|
368
|
+
if (flags.json) console.log(JSON.stringify(ix, null, 1));
|
|
369
|
+
else console.log(ix.map(x => [`${x.name} ${x.kind} ${x.items} items ${(x.bytes / 2 ** 20).toFixed(1)} MB`, ...x.people.map(p =>
|
|
370
|
+
` ${p.who} ${p.phase} ${p.pages} pages caught up ${p.caught_up ? when(p.caught_up) : 'never'}${p.error ? ` ${p.retry_at ? `again ${when(p.retry_at)}` : 'stopped'}: ${p.error}` : ''}`)].join('\n')).join('\n\n') || 'No indexes.');
|
|
307
371
|
} else if (cmd === 'runs' && args.length <= 1) {
|
|
308
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));
|
|
309
373
|
if (flags.json) console.log(JSON.stringify(rows, null, 1));
|
|
310
|
-
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 ?? ''}`);
|
|
311
375
|
} else if (cmd === 'costs' && args.length <= 1) {
|
|
312
|
-
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];
|
|
313
380
|
if (!key) throw new Error(USAGE);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
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 }))
|
|
317
385
|
.sort((a, b) => by === 'day' ? a.day.localeCompare(b.day) : b.cost - a.cost);
|
|
318
386
|
if (flags.json) console.log(JSON.stringify(out, null, 1));
|
|
319
387
|
else {
|
|
320
|
-
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]}`);
|
|
321
|
-
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`}`}`);
|
|
322
410
|
}
|
|
323
411
|
} else if (cmd === 'people' && args.length <= 1) {
|
|
324
412
|
// People as lines to edit and set: ROLE EMAIL for everyone, owner|member EMAIL-OR-GROUP for a workspace, each with a comment.
|
|
@@ -329,10 +417,10 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
329
417
|
: (await get('/users')).map(u => ({ kind: u.role, who: u.email, note: [u.disabled && 'disabled', last(u.last_login), `in ${u.workspaces.join(', ') || 'none'}`, u.outside.length && `runs outside them: ${u.outside.join(', ')}`] }));
|
|
330
418
|
if (typeof flags.set !== 'string') {
|
|
331
419
|
const w = Math.max(0, ...now.map(p => p.who.length));
|
|
332
|
-
for (const p of now) console.log(`${p.kind.padEnd(
|
|
420
|
+
for (const p of now) console.log(`${p.kind.padEnd(6)} ${p.who.padEnd(w)} # ${p.note.filter(Boolean).join('; ')}`);
|
|
333
421
|
if (!now.length) console.log('# no one is in it: only admins see it');
|
|
334
422
|
} else {
|
|
335
|
-
const kinds = ws ? ['owner', 'member'] : ['admin', '
|
|
423
|
+
const kinds = ws ? ['owner', 'member'] : ['admin', 'user'];
|
|
336
424
|
const want = readFileSync(flags.set === '-' ? 0 : flags.set, 'utf8').split('\n').map(l => l.replace(/#.*/, '').trim()).filter(Boolean).map(l => l.split(/\s+/));
|
|
337
425
|
const bad = want.find(([kind, who, more]) => !kinds.includes(kind) || !who || more);
|
|
338
426
|
if (bad) throw new Error(`each line is ${kinds.join('|')} ${ws ? 'EMAIL-OR-GROUP' : 'EMAIL'}, not: ${bad.join(' ')}`);
|
|
@@ -356,6 +444,10 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
356
444
|
const { text, logo } = (await get('/me')).brand;
|
|
357
445
|
console.log(text || logo ? `${text ?? 'no text'}, ${logo ? 'with a logo' : 'no logo'}` : 'no brand: the plain look');
|
|
358
446
|
}
|
|
447
|
+
} else if (cmd === 'can' && args.length <= 2) {
|
|
448
|
+
const [cap, list] = args, people = flags.clear ? [] : list?.split(',').map(p => p.trim()).filter(Boolean);
|
|
449
|
+
const all = await (await (people ? post('/capabilities', { cap, people }, 'PUT') : api('/capabilities'))).json();
|
|
450
|
+
for (const [c, who] of Object.entries(all)) if (!cap || c === cap) console.log(`${c}: ${who.join(', ') || 'admins only'}`);
|
|
359
451
|
} else if (cmd === 'user' && args.length >= 2) {
|
|
360
452
|
const [what, email, role] = args, at = `/users/${encodeURIComponent(email)}`;
|
|
361
453
|
if (what === 'add') await post('/users', { roles: { [email]: role ?? 'user' } }, 'PUT');
|