@rfany/rf 0.13.1 → 0.15.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 +83 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfany/rf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// rf for people: what the page does, from a shell or a desktop agent, as you, with a personal token made on the page (Tokens).
|
|
3
3
|
// Published to npm as @rfany/rf, from cli/. PATH is workspace/series/label, as `rf ls` prints it.
|
|
4
|
-
import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, rmdirSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { homedir, hostname } from 'node:os';
|
|
7
7
|
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
@@ -16,7 +16,8 @@ const USAGE = `rf login URL [TOKEN] without a TOKEN, through the
|
|
|
16
16
|
rf ls [--json] every workspace, series and instance you see, with its status, runner, asks waiting and wakes
|
|
17
17
|
rf waiting [--json] what waits on you: asks and notes, requests to start an instance or to use a
|
|
18
18
|
website in a workspace you own, proposals, expired logins, and hosts a run's browser on a
|
|
19
|
-
website
|
|
19
|
+
website of yours was refused that the server's check left, or for admins anyone's it rates
|
|
20
|
+
high risk or finds at an internal address
|
|
20
21
|
rf show PATH [--json] an instance: its items, the threads that wait on someone, by id, and its last run
|
|
21
22
|
rf log PATH [--since SEQ] [--follow] [--json] its log, a line an entry, after SEQ; --follow prints more as they come;
|
|
22
23
|
--json prints the entries as they are, a line each
|
|
@@ -30,7 +31,7 @@ rf --version rf's own version, to tell whether it's older t
|
|
|
30
31
|
rf comment PATH TEXT [--item ID] [--ref REF] [--thread cN] [--wake|--wait] a new thread, or a reply under comment cN, as to
|
|
31
32
|
an agent's ask; --wake starts a run on it, as --wait does, which prints what the agent says back
|
|
32
33
|
rf upload PATH FILE [--onto ITEM] [--output] [--wake]
|
|
33
|
-
rf signoff PATH cN [TEXT] [--wake] signs off the agent's ask cN,
|
|
34
|
+
rf signoff PATH cN [TEXT] [--wake] signs off the agent's ask cN, saying yes to it, which commits the folder
|
|
34
35
|
in your name; to say no, reply
|
|
35
36
|
rf react PATH [cN] up|down|none your thumbs up or down on comment cN, or on the instance, or none; quiet, open or closed
|
|
36
37
|
rf close PATH [--as-series NAME] [--wake] the runner makes it the record and an example,
|
|
@@ -50,27 +51,32 @@ rf new workspace NAME yours to own, for admins and those they grant
|
|
|
50
51
|
rf copy PATH LABEL [--creds OFFER,...] a closed or abandoned instance, copied into a new open one without its agent session
|
|
51
52
|
rf share PATH on|off [--creds OFFER,...] the series' people, and their agents, wake it as you, with those offers ticked;
|
|
52
53
|
off stops it, for its sharer or its workspace's owners
|
|
53
|
-
rf archive PATH [--undo] a workspace or a series leaves the sidebar
|
|
54
|
+
rf archive PATH [--undo] a workspace or a series leaves the sidebar, and nothing in it changes or runs, until --undo brings it back
|
|
54
55
|
rf request start|drop ID [--creds OFFER,...] [--wake] a request to start an instance, by the ID rf waiting and rf wakes
|
|
55
56
|
print; --wake runs the instance it starts
|
|
56
57
|
rf logins [--json] your logins, each with its state, keepalive and offers; you sign in to them on the page
|
|
57
58
|
rf logins offer|unoffer LOGIN SOURCE|OFFER what a login offers runs: Microsoft 365's (m365) mailboxes, sites, folders and
|
|
58
59
|
files, by address or link, a Databricks login's SQL warehouses, by link; unoffer takes the
|
|
59
60
|
OFFER rf logins lists
|
|
60
|
-
rf logins allow SITE HOST
|
|
61
|
-
|
|
61
|
+
rf logins allow SITE HOST [--person EMAIL] a host the pages of your website SITE need; once a grant to it is approved,
|
|
62
|
+
only within the domains it reaches, beyond which admins allow them, with --person; one at
|
|
63
|
+
an internal address an admin allows once, for everyone's websites
|
|
64
|
+
rf logins disallow SITE HOST a host your website SITE reaches no more, which stays refused, the server's check letting
|
|
65
|
+
it no more
|
|
62
66
|
rf logins signout LOGIN
|
|
63
|
-
rf
|
|
64
|
-
|
|
65
|
-
rf site
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
rf sites [--json] your websites, each with its address and the other hosts it reaches, with what the server's
|
|
68
|
+
check said of those it let it reach
|
|
69
|
+
rf site add NAME URL [--header NAME] a website of your own, by a NAME you choose, whose sign-in starts at URL, which you
|
|
70
|
+
sign in to on the page; --header names a header its sign-in needs that its pages never
|
|
71
|
+
send, such as x-bot-token, whose value you give as you sign in
|
|
72
|
+
rf site set NAME [--header NAME] [--keepalive PAGE] [--every 10m] [--writeback false]
|
|
73
|
+
your website NAME: a header its sign-in needs that its pages never send, such as
|
|
74
|
+
x-bot-token, whose value you give as you sign in, the page a login kept alive loads, by
|
|
75
|
+
address or path, else its address, and how often, 10m unless given, and whether a run's
|
|
76
|
+
browser writes its state back; admins set --internal true|false, with --person EMAIL for
|
|
77
|
+
someone's, for its browsers to reach internal hosts, and its hosts at internal addresses
|
|
78
|
+
everyone's websites, with no admin again, until one sets it false
|
|
79
|
+
rf site remove NAME your website NAME, with your login to it and your grants for it
|
|
74
80
|
rf site ask NAME WORKSPACE REASON to use your login to NAME in WORKSPACE's runs, for REASON, which one of its owners approves
|
|
75
81
|
or denies, seeing the server's check of the website, or an admin, where it rates it high
|
|
76
82
|
risk; a login no approved grant uses is signed out a week after you signed in, and once
|
|
@@ -84,6 +90,9 @@ rf wake PATH AT [--label LABEL] [--days DAYS] | rf wake --cancel ID
|
|
|
84
90
|
AT now, +<n>m|h|d or a date; PATH an open instance, or a series with LABEL; DAYS, such as
|
|
85
91
|
mon-fri, repeats it weekly at AT's time; rf ls shows each wake's ID
|
|
86
92
|
rf agents [WORKSPACE] [--set FILE|-] the company's AGENTS.md, or a workspace's; setting the company's is for admins
|
|
93
|
+
rf readers WORKSPACE [add|remove OTHER] the workspaces whose agents read WORKSPACE and those its own read, as each one's
|
|
94
|
+
owners let them; its owners let OTHER's agents read it, one they see, and its owners or
|
|
95
|
+
OTHER's take that off; OTHER's people see what its agents read
|
|
87
96
|
rf skills
|
|
88
97
|
rf skill pull ID [DIR] [--version N] the newest version, or N, into DIR, ./ID by default, new or empty, as push reads it
|
|
89
98
|
rf skill versions ID
|
|
@@ -116,6 +125,9 @@ rf people [--set FILE|-] [-n] [--force] everyone as lines of ROLE EMAIL, each
|
|
|
116
125
|
rf user add EMAIL [admin] | role EMAIL admin|user [--force] | disable EMAIL | enable EMAIL | signout EMAIL | remove EMAIL
|
|
117
126
|
rf egress [add|remove HOST] the hosts runs may reach beyond package registries, GitHub and documentation sites, such as
|
|
118
127
|
api.example.com or *.example.org; admins add and remove them
|
|
128
|
+
rf internal [remove HOST] [--json] the hosts at internal addresses admins let every website reach, each with who let it and
|
|
129
|
+
when, as rf site set NAME --internal true or allowing one does; remove takes one out, after
|
|
130
|
+
which everyone's websites at it wait for an admin again
|
|
119
131
|
rf connection set NAME TYPE an outside system runs reach as their runner, by a login each person makes: graph,
|
|
120
132
|
Microsoft 365, or databricks, Azure Databricks, as each person adds what their login
|
|
121
133
|
offers; websites are rf site's
|
|
@@ -146,14 +158,14 @@ What there is
|
|
|
146
158
|
- A comment starts a thread, on the instance or on an item, at a cell such as Base!C25 or a line of a markdown file by its
|
|
147
159
|
opening words, and replies go under any comment in it, cN by its seq, a thread's id its first comment's. An ask is the agent's
|
|
148
160
|
comment that waits on someone, the one it names or else the runner, until someone replies under it. rf ls says how many asks
|
|
149
|
-
wait in each instance. Reactions, thumbs up or down, are quiet signals kept for later.
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
wait in each instance. Reactions, thumbs up or down, are quiet signals kept for later. Anyone
|
|
162
|
+
who sees the instance may sign an ask off, saying yes, which commits the instance's folder to its history, .git in it, as it
|
|
163
|
+
is then, as closing does. Whose sign-off counts, and for what, is the series' call.
|
|
152
164
|
|
|
153
165
|
What rf pull copies, the folders as the agent sees them
|
|
154
166
|
AGENTS.md the company's conventions; <workspace>/AGENTS.md the workspace's
|
|
155
167
|
<workspace>/<series>/<label>/
|
|
156
|
-
screen.json the screen: {rev, status, items: [{id, name, kind, file, from, headline, source, destination
|
|
168
|
+
screen.json the screen: {rev, status, items: [{id, name, kind, file, from, headline, source, destination}]}
|
|
157
169
|
log.jsonl every event, by seq: by is a person's email, "server" or "agent"; op is upload, comment (thread, item,
|
|
158
170
|
ref, parent, text, files, ask, to), signoff (someone's, on the ask it names, with its commit), react,
|
|
159
171
|
commit, point and item (the screen changing), run, done (its cost, or error), close, and the rest
|
|
@@ -169,7 +181,7 @@ The copy is read-only: only rf's commands change what's on the server.
|
|
|
169
181
|
|
|
170
182
|
Usual work
|
|
171
183
|
- What waits on me: rf waiting, then rf show PATH, which names each comment that waits by its id.
|
|
172
|
-
- Answer an ask: rf comment PATH TEXT --thread cN --wait, which prints what the agent says back; sign off
|
|
184
|
+
- Answer an ask: rf comment PATH TEXT --thread cN --wait, which prints what the agent says back; or sign it off:
|
|
173
185
|
rf signoff PATH cN [TEXT] --wake, for the agent to carry on. Close an
|
|
174
186
|
instance once it's the record: rf close PATH.
|
|
175
187
|
- Take an instance over: rf creds PATH lists the offers of your logins, and rf takeover PATH --creds OFFER,... ticks them.
|
|
@@ -276,11 +288,16 @@ function write(path , data , mtime ) {
|
|
|
276
288
|
|
|
277
289
|
// A path the server named, under `base`, or undefined where a name in it can't be one here: on Windows a name may hold \ or :, which
|
|
278
290
|
// would put the file elsewhere, even in another workspace's folder, or another file's stream; or name a device, such as CON; or end
|
|
279
|
-
// in a dot or a space, which Windows drops.
|
|
291
|
+
// in a dot or a space, which Windows drops. A link where one of its folders goes, or `base`, would take the file elsewhere too, and is refused.
|
|
280
292
|
const under = (base , rel ) => {
|
|
281
293
|
const names = rel.split('/');
|
|
282
294
|
if (names.some(n => !n || n === '.' || n === '..' || basename(n) !== n
|
|
283
295
|
|| (process.platform === 'win32' && (/[<>:"|?*\x00-\x1f]|[. ]$/.test(n) || /^(con|prn|aux|nul|com\d|lpt\d)(\.|$)/i.test(n))))) return undefined;
|
|
296
|
+
let folder = base;
|
|
297
|
+
for (const name of ['', ...names.slice(0, -1)]) {
|
|
298
|
+
folder = join(folder, name);
|
|
299
|
+
if (lstatSync(folder, { throwIfNoEntry: false })?.isSymbolicLink()) throw new Error(`${folder} is a symlink: remove it or pull into another directory`);
|
|
300
|
+
}
|
|
284
301
|
return join(base, ...names);
|
|
285
302
|
};
|
|
286
303
|
|
|
@@ -290,7 +307,8 @@ const globs = excludes.map(p => [p.replace(/^\/|\/$/g, '').includes('/'), new Re
|
|
|
290
307
|
const excluded = (rel ) => globs.some(([whole, re]) => rel.split('/').some((name, k, all) => re.test(whole ? all.slice(0, k + 1).join('/') : name)));
|
|
291
308
|
|
|
292
309
|
// Copies PATH's files into DIR as rsync does, from the server only and whole: a file whose size or time differ from the server's is
|
|
293
|
-
// fetched, and given the server's time, so the next pull compares against it. Nothing is kept besides the files.
|
|
310
|
+
// fetched, and given the server's time, so the next pull compares against it. Nothing is kept besides the files. DIR may be a link, as the
|
|
311
|
+
// person who names it chose; no folder in it may.
|
|
294
312
|
async function pull(path , dir ) {
|
|
295
313
|
const at = path.replace(/^\/+/, ''), from = at.replace(/\/+$/, ''), dry = !!flags['dry-run'];
|
|
296
314
|
const size = /^(\d+)([KMG]?)$/i.exec(String(flags['max-size'] ?? '0'));
|
|
@@ -298,7 +316,8 @@ async function pull(path , dir ) {
|
|
|
298
316
|
const max = flags['max-size'] === undefined ? Infinity : Number(size[1]) * 1024 ** ' KMG'.indexOf(size[2].toUpperCase() || ' ');
|
|
299
317
|
const list = await get(`/api/files?path=${encodeURIComponent(from)}`);
|
|
300
318
|
if (!list.length) throw new Error(`nothing you can see at ${path}`);
|
|
301
|
-
const
|
|
319
|
+
const to = existsSync(dir) ? realpathSync(dir) : resolve(dir);
|
|
320
|
+
const into = !from || at.endsWith('/') ? to : under(to, from.slice(from.lastIndexOf('/') + 1)), rel = (f ) => f.path.slice(from ? from.length + 1 : 0);
|
|
302
321
|
if (!into) throw new Error(`${from} can't be a name here: pull ${from}/ into a folder of your choosing`);
|
|
303
322
|
let fetched = 0, same = 0, deleted = 0, failed = 0, big = 0;
|
|
304
323
|
const fetches = [];
|
|
@@ -386,8 +405,8 @@ if (cmd === 'login' && url) {
|
|
|
386
405
|
...series.flatMap(x => x.requests.filter(r => mine(r.who)).map(r => ({ kind: 'request', path: x.path, since: r.at, id: r.id, text: `${r.from} asks to start ${r.label}` }))),
|
|
387
406
|
...all.filter(w => w.manage && w.proposal?.into === w.id).map(({ proposal: p }) => ({ kind: 'proposal', 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`}` })),
|
|
388
407
|
...s.expired.filter(e => e.who === me.email).map(e => ({ kind: 'expired', login: e.login, holding: e.holding, text: `your ${e.login} login expired` })),
|
|
389
|
-
...series.flatMap(x => x.instances.flatMap(i => i.refused.map(r => ({ kind: 'refused', path: `${x.path}/${i.label}`, since: r.at, site: r.site, hosts: r.hosts, text: `run ${r.run}'s browser on ${r.site} was refused ${r.hosts.join(', ')}` })))),
|
|
390
|
-
...all.filter(w => w.manage).flatMap(w => w.grants.filter(g => g.state === 'pending').map(g => ({ kind: 'grant', path: w.name, since: g.at, id: g.id, text: `${g.person} asks to use ${g.site} here: ${g.reason} (${g.check?.risk ? `${g.check.risk} risk` : 'not checked'})` }))),
|
|
408
|
+
...series.flatMap(x => x.instances.flatMap(i => i.refused.map(r => ({ kind: 'refused', path: `${x.path}/${i.label}`, since: r.at, site: r.site, hosts: r.hosts, person: r.login, why: r.why, text: `run ${r.run}'s browser on ${r.login}'s ${r.site} was refused ${r.hosts.map((h ) => r.why[h] ? `${h} (${r.why[h]})` : h).join(', ')}` })))),
|
|
409
|
+
...all.filter(w => w.manage).flatMap(w => w.grants.filter(g => g.state === 'pending').map(g => ({ kind: 'grant', path: w.name, since: g.at, id: g.id, text: `${g.person} asks to use ${g.site}, at ${g.url}, here: ${g.reason} (${g.check?.risk ? `${g.check.risk} risk` : 'not checked'})` }))),
|
|
391
410
|
];
|
|
392
411
|
if (flags.json) console.log(JSON.stringify(rows, null, 1));
|
|
393
412
|
else console.log(rows.map(r => `${r.kind} ${r.path ?? r.login}${r.since ? ` since ${when(r.since)}` : ''}${r.id ? `, ${r.kind === 'grant' ? 'grant' : 'request'} ${r.id}` : ''}: ${r.text.split('\n')[0].slice(0, 120)}`).join('\n') || 'Nothing waits on you.');
|
|
@@ -423,8 +442,8 @@ if (cmd === 'login' && url) {
|
|
|
423
442
|
} else if (cmd === 'pull' && args.length === 2) await pull(args[0], args[1]);
|
|
424
443
|
else if (cmd === 'comment' && args.length === 2) {
|
|
425
444
|
const { at } = await instanceAt(args[0]);
|
|
426
|
-
await post(`${at}/comment`, { text: args[1], item: flags.item, ref: flags.ref, thread: flags.thread, quiet: !flags.wake && !flags.wait });
|
|
427
|
-
const { log, runner } = await get(at), {
|
|
445
|
+
const posted = await post(`${at}/comment`, { text: args[1], item: flags.item, ref: flags.ref, thread: flags.thread, quiet: !flags.wake && !flags.wait });
|
|
446
|
+
const seq = Number(posted.headers.get('X-RF-Comment-Seq')), { log, runner } = await get(at), { note } = log.find(e => e.seq === seq);
|
|
428
447
|
if (note) console.log(`a note for the runner, ${runner.by}, seq ${seq}: it starts no run until they act`);
|
|
429
448
|
else if (!flags.wait) console.log(`commented, seq ${seq}`);
|
|
430
449
|
else for (;;) {
|
|
@@ -446,8 +465,8 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
446
465
|
console.log(`signed off ${args[1]}`);
|
|
447
466
|
} else if (['close', 'abandon', 'interrupt'].includes(cmd) && args.length === 1) {
|
|
448
467
|
const { series, at } = await instanceAt(args[0]);
|
|
449
|
-
if (cmd === 'close' && typeof flags['as-series'] === 'string') await post(`/api/series/${series.id}/promote`, { name: flags['as-series'] });
|
|
450
468
|
await post(`${at}/${cmd}`, { quiet: !flags.wake });
|
|
469
|
+
if (cmd === 'close' && typeof flags['as-series'] === 'string') await post(`/api/series/${series.id}/promote`, { name: flags['as-series'] });
|
|
451
470
|
console.log(`${cmd === 'close' ? 'closed' : `${cmd}ed`} ${args[0]}`);
|
|
452
471
|
} else if (cmd === 'takeover' && args.length === 1) {
|
|
453
472
|
await post(`${(await instanceAt(args[0])).at}/takeover`, { logins: ticks() });
|
|
@@ -470,7 +489,9 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
470
489
|
else await post(`/api/workspaces/${(await workspaceNamed(w)).id}`, { name: args[1] }, 'PUT');
|
|
471
490
|
console.log(`renamed ${args[0]} ${args[1]}`);
|
|
472
491
|
} else if (cmd === 'new' && args[0] === 'task' && [2, 3].includes(args.length)) {
|
|
473
|
-
const
|
|
492
|
+
const workspace = await workspaceNamed(args[1]);
|
|
493
|
+
if (workspace.series.some(s => s.name === args[2])) throw new Error(`${args[2]} exists`);
|
|
494
|
+
const { instance } = await (await post('/api/series', { workspace: workspace.id, single: true, logins: ticks() })).json();
|
|
474
495
|
if (args[2]) await post(`/api/instances/${instance}/rename?as=${encodeURIComponent(args[2])}`, {});
|
|
475
496
|
if (typeof flags.comment === 'string') await post(`/api/instances/${instance}/comment`, { text: flags.comment, quiet: !flags.wake });
|
|
476
497
|
console.log(`made ${await pathOf(instance)}${consent(ticks())}`);
|
|
@@ -504,17 +525,22 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
504
525
|
// A website's login offers itself alone.
|
|
505
526
|
for (const o of l.offers.filter(o => o.id !== l.id)) console.log(` offers ${o.id} ${o.name}`);
|
|
506
527
|
}
|
|
507
|
-
} else if (cmd === 'logins' && ['offer', 'unoffer', 'allow'].includes(args[0]) && args.length === 3) {
|
|
528
|
+
} else if (cmd === 'logins' && ['offer', 'unoffer', 'allow', 'disallow'].includes(args[0]) && args.length === 3) {
|
|
508
529
|
const [what, login, x] = args, at = `/logins/${encodeURIComponent(login)}`;
|
|
509
530
|
if (what === 'offer') await post(`${at}/offers`, { add: x });
|
|
510
531
|
else if (what === 'unoffer') await api(`${at}/offers/${encodeURIComponent(x)}`, { method: 'DELETE' });
|
|
511
|
-
else await
|
|
512
|
-
|
|
532
|
+
else if (what === 'disallow') await api(`/logins/web/${encodeURIComponent(login)}/hosts/${encodeURIComponent(x)}`, { method: 'DELETE' });
|
|
533
|
+
else await post(`/logins/web/${encodeURIComponent(login)}/hosts${flags.person ? `?person=${encodeURIComponent(String(flags.person))}` : ''}`, { host: x });
|
|
534
|
+
console.log(`${login} ${{ offer: 'offers', unoffer: 'no longer offers', allow: 'reaches', disallow: 'no longer reaches' }[what]} ${x}`);
|
|
535
|
+
} else if (cmd === 'sites' && !args.length) {
|
|
536
|
+
const all = await get('/logins/sites');
|
|
537
|
+
if (flags.json) console.log(JSON.stringify(all, null, 1));
|
|
538
|
+
else for (const [name, w] of Object.entries (all)) console.log(`${name} ${w.url}${w.hosts.map((h ) => `\n reaches ${h}${w.checks?.[h]?.verdict === 'pass' ? `: ${w.checks[h].why}` : ''}`).join('')}`);
|
|
513
539
|
} else if (cmd === 'site' && args[0] === 'add' && args.length === 3) {
|
|
514
|
-
const { site
|
|
515
|
-
console.log(
|
|
540
|
+
const { site } = await (await post('/logins/sites', { name: args[1], url: args[2], header: flags.header })).json();
|
|
541
|
+
console.log(`added ${site}: sign in to it at ${url}/#logins, then rf site ask ${site} WORKSPACE REASON`);
|
|
516
542
|
} else if (cmd === 'site' && args[0] === 'set' && args.length === 2) {
|
|
517
|
-
await post(`/logins/sites/${encodeURIComponent(args[1])}`, flags, 'PATCH');
|
|
543
|
+
await post(`/logins/sites/${encodeURIComponent(args[1])}${flags.person ? `?person=${encodeURIComponent(String(flags.person))}` : ''}`, { ...flags, person: undefined }, 'PATCH');
|
|
518
544
|
console.log('saved');
|
|
519
545
|
} else if (cmd === 'site' && args[0] === 'remove' && args.length === 2) {
|
|
520
546
|
await api(`/logins/sites/${encodeURIComponent(args[1])}`, { method: 'DELETE' });
|
|
@@ -522,12 +548,12 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
522
548
|
} else if (cmd === 'site' && args[0] === 'ask' && args.length === 4) {
|
|
523
549
|
const { id, check: c } = await (await post('/grants', { site: args[1], workspace: (await workspaceNamed(args[2])).id, reason: args[3] })).json();
|
|
524
550
|
console.log(`asked, as grant ${id}: ${c.risk === 'high' ? 'an admin approves or denies it, as the check rates it high risk' : `one of ${args[2]}'s owners approves or denies it`}\n${!c.risk ? `not checked: ${c.error}`
|
|
525
|
-
: `check: ${c.risk} risk${c.flags.length ? ` (${c.flags.join('; ')})` : ''}. ${c.summary}${c.
|
|
551
|
+
: `check: ${c.risk} risk${c.flags.length ? ` (${c.flags.join('; ')})` : ''}. ${c.summary}${c.hosts.length ? ` Approving lets it reach ${c.hosts.join(', ')}.` : ''}`}`);
|
|
526
552
|
} else if (cmd === 'grants' && args.length <= 1) {
|
|
527
553
|
const [all, ws] = await Promise.all([get('/grants'), get('/api')]), name = (id ) => ws.find(w => w.id === id)?.name ?? id;
|
|
528
554
|
const shown = all.filter(g => !args[0] || name(g.workspace) === args[0]);
|
|
529
555
|
if (flags.json) console.log(JSON.stringify(shown.map(g => ({ ...g, workspace: name(g.workspace) })), null, 1));
|
|
530
|
-
else for (const g of shown) console.log(`${g.id} ${g.state} ${g.site} in ${name(g.workspace)} for ${g.person}, since ${when(g.at)}: ${g.reason}${g.by ? `; ${g.state} by ${g.by}${g.text ? `: ${g.text}` : ''}` : ''} (${g.check?.risk ? `${g.check.risk} risk` : 'not checked'})`);
|
|
556
|
+
else for (const g of shown) console.log(`${g.id} ${g.state} ${g.site} at ${g.url} in ${name(g.workspace)} for ${g.person}, since ${when(g.at)}: ${g.reason}${g.by ? `; ${g.state} by ${g.by}${g.text ? `: ${g.text}` : ''}` : ''} (${g.check?.risk ? `${g.check.risk} risk` : 'not checked'})`);
|
|
531
557
|
} else if (cmd === 'grant' && ['approve', 'deny'].includes(args[0]) && [2, 3].includes(args.length)) {
|
|
532
558
|
await post(`/grants/${args[1]}`, { approve: args[0] === 'approve', text: args[2] });
|
|
533
559
|
console.log(args[0] === 'approve' ? 'approved' : 'denied');
|
|
@@ -561,6 +587,16 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
561
587
|
await (ws ? post(`/api/workspaces/${ws.id}`, { agents: text }, 'PUT') : api('/agents', { method: 'PUT', body: text }));
|
|
562
588
|
console.log('saved');
|
|
563
589
|
}
|
|
590
|
+
} else if (cmd === 'readers' && args.length === 1) {
|
|
591
|
+
const ws = await workspaceNamed(args[0]);
|
|
592
|
+
if (flags.json) console.log(JSON.stringify({ readers: ws.readers, reads: ws.reads }, null, 1));
|
|
593
|
+
else console.log([...ws.readers.map(r => `${r.name} reads ${ws.name}`), ...ws.reads.map(r => `${ws.name} reads ${r.name}`)].join('\n') || `${ws.name} reads no other workspace, and none reads it`);
|
|
594
|
+
} else if (cmd === 'readers' && args.length === 3 && ['add', 'remove'].includes(args[1])) {
|
|
595
|
+
// A workspace you don't see, whose agents' reading of one of yours you take off, is found among what yours read.
|
|
596
|
+
const all = await get('/api'), [ws, other] = [args[0], args[2]].map(name => all.find(w => w.name === name) ?? all.flatMap(w => w.reads).find(r => r.name === name));
|
|
597
|
+
if (!ws || !other) throw new Error(`no workspace ${ws ? args[2] : args[0]}`);
|
|
598
|
+
await post(`/api/workspaces/${ws.id}/readers/${other.id}`, {}, args[1] === 'add' ? 'PUT' : 'DELETE');
|
|
599
|
+
console.log(args[1] === 'add' ? `${other.name}'s agents read ${ws.name} from their next run` : `${other.name}'s agents no longer read ${ws.name}`);
|
|
564
600
|
} else if (cmd === 'skill' && args[0] === 'push' && args[1]) {
|
|
565
601
|
const files = Object.fromEntries(readdirSync(args[1], { recursive: true, withFileTypes: true }).filter(d => d.isFile())
|
|
566
602
|
.map(d => [relative(args[1], join(d.parentPath, d.name)).split(sep).join('/'), readFileSync(join(d.parentPath, d.name)).toString('base64')]));
|
|
@@ -664,6 +700,14 @@ else if (cmd === 'comment' && args.length === 2) {
|
|
|
664
700
|
let hosts = await (await api('/egress')).json();
|
|
665
701
|
if (args.length) hosts = await (await post('/egress', { hosts: args[0] === 'add' ? [...new Set([...hosts, args[1]])] : hosts.filter(h => h !== args[1]) }, 'PUT')).json();
|
|
666
702
|
console.log(hosts.join('\n'));
|
|
703
|
+
} else if (cmd === 'internal' && (!args.length || (args.length === 2 && args[0] === 'remove'))) {
|
|
704
|
+
const hosts = args.length ? await (await api(`/internal/${encodeURIComponent(args[1])}`, { method: 'DELETE' })).json() : await get('/internal');
|
|
705
|
+
if (flags.json) console.log(JSON.stringify(hosts, null, 1));
|
|
706
|
+
else {
|
|
707
|
+
const w = Math.max(0, ...Object.keys(hosts).map(h => h.length));
|
|
708
|
+
for (const [h, { by, at }] of Object.entries(hosts)) console.log(`${h.padEnd(w)} ${when(at)} ${by}`);
|
|
709
|
+
if (!Object.keys(hosts).length) console.log('none: an admin lets websites reach one with rf site set NAME --internal true');
|
|
710
|
+
}
|
|
667
711
|
} else if (cmd === 'people' && args.length <= 1) {
|
|
668
712
|
// People as lines to edit and set: ROLE EMAIL for everyone, owner|member EMAIL-OR-GROUP for a workspace, each with a comment.
|
|
669
713
|
const ws = args[0] === undefined ? undefined : await workspaceNamed(args[0]);
|