@rfany/rf 0.20.3 → 0.20.5

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.
Files changed (3) hide show
  1. package/README.md +9 -4
  2. package/package.json +1 -1
  3. package/rf.mjs +156 -26
package/README.md CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  People's command line for [rollforward](https://github.com/spoj/rollforward): what its page does, from a shell or a desktop agent, as you.
4
4
 
5
- npm i -g @rfany/rf
6
- rf login https://rollforward.example.com
5
+ Run with `npx` so you always stay on the latest version automatically:
6
+
7
+ npx @rfany/rf@latest login https://rollforward.example.com
8
+
9
+ Or use short-lived Entra ID tokens via Azure CLI (no static token saved to disk; requires HTTPS off loopback and an explicit `--resource api://<app-id>`, plus an initial browser sign-in to link your account and establish run-owner sign-in):
10
+
11
+ npx @rfany/rf@latest login https://rollforward.example.com --az --resource api://<app-id>
7
12
 
8
13
  rf opens the page, which asks you to allow it if it shows the same code as rf; or make a token on the page, under Tokens, and
9
- `rf login URL TOKEN`. `rf` alone lists the commands and `rf help COMMAND` gives one's usage; `rf help` is the guide for an agent, read before it first uses rf. Without saved config, help works offline; once signed in, it reads your current capabilities from the server.
14
+ `npx @rfany/rf@latest login URL TOKEN`. `rf` alone lists the commands and `rf help COMMAND` gives one's usage; `rf help` is the guide for an agent, read before it first uses rf. Without saved config, help works offline; once signed in, it reads your current capabilities from the server.
10
15
 
11
- `rf series owner WORKSPACE/SERIES EMAIL` explicitly transfers the whole series, not one instance; only its current owner or a workspace manager may do it. Old runs stop and execution consent is cleared. The incoming owner selects a series-wide ceiling with `rf series credentials WORKSPACE/SERIES --set OFFER,... --autonomous false`, or `--clear` for an explicit empty selection. The owner's acts and answers by whom the agent's ask named start runs under current consent. Other collaborators' words stay notes. Scheduled/autonomous execution needs `--autonomous true`. `rf new instance` never changes credentials; `rf new task` without `--creds` or `--clear` establishes no execution consent.
16
+ `rf series owner WORKSPACE/SERIES EMAIL` explicitly transfers the whole series, not one instance; only its current owner or a workspace manager may do it. Old runs stop and execution consent is cleared. The incoming owner selects series credentials with `rf series credentials WORKSPACE/SERIES --set OFFER,... --autonomous false`, or `--clear` for an explicit empty selection. The owner's acts and answers by whom the agent's ask named start runs under current consent. Other collaborators' words stay notes. Scheduled/autonomous execution needs `--autonomous true`. `rf new instance` never changes credentials; `rf new task` without `--creds` or `--clear` establishes no execution consent.
12
17
 
13
18
  `rf site ask NAME WORKSPACE REASON` asks its owners to use your login there, or approves it at once where you may. `rf grants` describes the system and what runs may do; general platforms and high-risk or failed checks need an admin. Only admins allow hosts, with `rf logins allow SITE HOST --person EMAIL`; you remove one with `rf logins disallow SITE HOST`.
14
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rfany/rf",
3
- "version": "0.20.3",
3
+ "version": "0.20.5",
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
@@ -3,7 +3,7 @@
3
3
  // Published to npm as @rfany/rf, from cli/. PATH is workspace/series/label, as `rf ls` prints it.
4
4
  import { randomBytes } from 'node:crypto';
5
5
  import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, utimesSync, writeFileSync, } from 'node:fs';
6
- import { spawn } from 'node:child_process';
6
+ import { execFileSync, spawn } from 'node:child_process';
7
7
  import { homedir, hostname } from 'node:os';
8
8
  import { basename, dirname, join, relative, resolve, sep } from 'node:path';
9
9
  import { parseArgs } from 'node:util';
@@ -15,12 +15,12 @@ process.on('uncaughtException', e => {
15
15
  });
16
16
 
17
17
  const usage = (c , vpn = false, admin = false) => {
18
- const all = `rf login URL [TOKEN] without a TOKEN, through the browser: type rf's code on the page, and allow it
18
+ const all = `rf login URL [TOKEN] [--az [--resource URI]] without a TOKEN, through the browser; with --az, short-lived Entra tokens via Azure CLI (no token on disk); run via npx @rfany/rf@latest
19
19
  rf ls [--mine] [--json] every workspace, series and instance you see, with its status, owner, asks waiting and wakes;
20
20
  --mine, only open instances of series you own
21
- rf waiting [--json] what waits on you: asks, proposals, requests and expired logins; also note notices (FYI).
22
- Only admins see hosts a run's browser was refused that the server rates high or finds
23
- at an internal address
21
+ rf waiting [--json] [--dismiss-settled] what waits on you: asks, proposals, requests and expired logins; also note notices (FYI).
22
+ --dismiss-settled dismisses all your settled note notices. Only admins see hosts a
23
+ run's browser was refused that the server rates high or finds at an internal address
24
24
  rf show PATH [--json] an instance: its items, the threads that wait on someone, by id, and its last run
25
25
  rf log PATH [--since SEQ] [--follow] [--json] its log, a line an entry, after SEQ; --follow prints more as they come;
26
26
  --json prints the entries as they are, a line each
@@ -62,7 +62,7 @@ rf series owner SERIES [EMAIL] [--json] the whole series' owner; EMAIL transfe
62
62
  clearing consent; only its current owner or a workspace manager may transfer it
63
63
  rf series credentials SERIES [--set OFFER,...|--clear] [--autonomous true|false] [--json]
64
64
  credentials for every instance; only the owner saves consent, explicitly including [] with
65
- --clear; saving requires --autonomous true|false; no credentials or schedules transfer
65
+ --clear; saving requires --autonomous true|false; no credentials transfer (schedules pause until opted in)
66
66
  rf rename PATH NAME an instance, a series or a workspace, by its path
67
67
  rf new task WORKSPACE [LABEL] [--creds OFFER,...|--clear] [--autonomous true|false] [--comment TEXT [--wake]] a one-off task, Untitled until LABEL or its
68
68
  first comment names it; --wake starts its run on the comment; without --creds or --clear,
@@ -78,8 +78,9 @@ rf logins [--json] your logins, each with its state, keepalive an
78
78
  rf logins offer|unoffer LOGIN SOURCE|OFFER what a login offers runs: Microsoft 365's (m365) mailboxes, sites, folders and
79
79
  files, by address or link, a Databricks login's SQL warehouses, by link; unoffer takes the
80
80
  OFFER rf logins lists
81
- rf logins allow SITE HOST --person EMAIL admins alone allow a host the server left refused; one at an internal address
81
+ rf logins allow SITE HOST --person EMAIL [--rev REV] admins alone allow a host the server left refused; one at an internal address
82
82
  is allowed once for everyone's websites
83
+ rf logins refuse SITE HOST [--person EMAIL] [--rev REV] admins alone keep a refused host blocked so it leaves Waiting on you
83
84
  rf logins disallow SITE HOST a host your website SITE reaches no more, which stays refused, the server's check letting
84
85
  it no more
85
86
  rf logins signout LOGIN${vpn ? '\nrf vpns [--json] client VPNs and whether you are connected to each; sign in on the page' : ''}
@@ -234,7 +235,7 @@ Usual work
234
235
  - Give an input or a corrected output: rf upload PATH FILE [--onto ITEM] [--output], with --wake on the last for a run on them
235
236
  all.
236
237
  - Start an instance: rf new instance SERIES LABEL --wake, only as the series owner. Scheduled wakes need that owner's
237
- autonomous opt-in and keep their authorized credential snapshot; collaborators' wakes become requests for the owner.
238
+ autonomous opt-in and use their current series credentials at fire time; collaborators' wakes become requests for the owner.
238
239
  A one-off: rf new task WORKSPACE --clear --comment TEXT --wake. Promotion with rf new series PATH NAME keeps its owner.
239
240
  - Tell a series something for its runs, or while no instance is open: rf comment SERIES TEXT, which starts no run.
240
241
  rf comment SERIES lists its notes; rf comment --mine lists your notes. Settle an informing note with
@@ -286,7 +287,7 @@ if (cmd === 'comment' || cmd === 'settle') {
286
287
  } else for (let i = 0; i < argv.length; i++) {
287
288
  const flag = argv[i] === '-n' ? 'dry-run' : argv[i] === '-d' ? 'delay' : argv[i].match(/^--(.+)$/)?.[1];
288
289
  if (!flag) args.push(argv[i]);
289
- else if (['wait', 'wake', 'output', 'delete', 'dry-run', 'force', 'json', 'failed', 'running', 'clear', 'follow', 'superseded', 'undo', 'by-amount', 'yes', 'mine', 'daily', 'all'].includes(flag)) flags[flag] = true;
290
+ else if (['wait', 'wake', 'output', 'delete', 'dry-run', 'force', 'json', 'failed', 'running', 'clear', 'follow', 'superseded', 'undo', 'by-amount', 'yes', 'mine', 'daily', 'all', 'az', 'dismiss-settled'].includes(flag)) flags[flag] = true;
290
291
  else if (argv[i + 1] === undefined) throw new Error(`--${flag} takes a value`);
291
292
  else if (flag === 'exclude') excludes.push(argv[++i]);
292
293
  else flags[flag] = argv[++i];
@@ -301,10 +302,69 @@ if ((!cmd || cmd === 'help') && !existsSync(config)) {
301
302
  process.exit();
302
303
  }
303
304
  if (cmd !== 'login' && !existsSync(config)) throw new Error('sign in first: rf login URL');
304
- let { url, token } = cmd === 'login' ? { url: args[0]?.replace(/\/$/, ''), token: args[1] } : JSON.parse(readFileSync(config, 'utf8'));
305
+ let { url, token, auth, resource } = cmd === 'login'
306
+ ? { url: args[0]?.replace(/\/$/, ''), token: args[1], auth: flags.az ? 'az' : (typeof flags.auth === 'string' ? flags.auth : undefined), resource: typeof flags.resource === 'string' ? flags.resource : undefined }
307
+ : JSON.parse(readFileSync(config, 'utf8'));
308
+
309
+ function assertSafeAzUrl(rawUrl ) {
310
+ let parsed ;
311
+ try {
312
+ parsed = new URL(rawUrl);
313
+ } catch {
314
+ throw new Error(`invalid server URL: ${rawUrl}`);
315
+ }
316
+ const host = parsed.hostname.toLowerCase();
317
+ const isLoopback = host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]';
318
+ if (parsed.protocol !== 'https:' && !isLoopback) {
319
+ throw new Error('--az requires https:// off loopback');
320
+ }
321
+ }
322
+
323
+ function assertValidAzResource(res ) {
324
+ if (!res || res.startsWith('-') || !/^[A-Za-z0-9:/._-]+$/.test(res)) {
325
+ throw new Error('invalid --resource for --az; pass an explicit Entra resource such as --resource api://<app-id>');
326
+ }
327
+ }
328
+
329
+ function jwtExpMs(tok ) {
330
+ try {
331
+ const parts = tok.split('.');
332
+ if (parts.length !== 3) return 0;
333
+ const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
334
+ return typeof payload?.exp === 'number' ? payload.exp * 1000 : 0;
335
+ } catch {
336
+ return 0;
337
+ }
338
+ }
339
+
340
+ let cachedAzToken ;
341
+ function bearerToken() {
342
+ if (auth === 'az') {
343
+ if (cachedAzToken && (cachedAzToken.expMs === 0 || cachedAzToken.expMs - Date.now() > 300_000)) {
344
+ return cachedAzToken.token;
345
+ }
346
+ assertSafeAzUrl(url);
347
+ if (!resource) throw new Error('missing resource for --az auth; run rf login URL --az --resource api://<app-id>');
348
+ assertValidAzResource(resource);
349
+ const azBin = process.env.RF_AZ_BIN || 'az';
350
+ const azArgs = ['account', 'get-access-token', '--resource', resource, '--query', 'accessToken', '-o', 'tsv'];
351
+ try {
352
+ const out = (process.platform === 'win32'
353
+ ? execFileSync('cmd.exe', ['/d', '/s', '/c', azBin, ...azArgs], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })
354
+ : execFileSync(azBin, azArgs, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] })).trim();
355
+ if (!out) throw new Error('empty access token returned by az');
356
+ cachedAzToken = { token: out, expMs: jwtExpMs(out) };
357
+ return out;
358
+ } catch (e ) {
359
+ const stderr = String(e?.stderr ?? '').trim();
360
+ throw new Error(`az account get-access-token failed: ${stderr || e.message}`);
361
+ }
362
+ }
363
+ return token;
364
+ }
305
365
 
306
366
  async function api(path , init = {}, accept = []) {
307
- const r = await fetch(url + path, { ...init, headers: { authorization: `Bearer ${token}` } });
367
+ const r = await fetch(url + path, { ...init, headers: { authorization: `Bearer ${bearerToken()}` } });
308
368
  if (!r.ok && !accept.includes(r.status)) throw new Error(`${init.method ?? 'GET'} ${path}: ${r.status} ${await r.text()}`);
309
369
  return r;
310
370
  }
@@ -347,7 +407,7 @@ async function workspaceNamed(name ) {
347
407
  const pathOf = async (id ) => (await get('/api')).flatMap(w => w.series.flatMap(s => s.instances.filter(i => i.id === id).map(i => `${w.name}/${s.name}/${i.label}`)))[0];
348
408
  // Explicit series-wide offer selection.
349
409
  const ticks = () => flags.clear ? [] : String(flags.creds ?? flags.set ?? '').split(',').map(o => o.trim()).filter(Boolean);
350
- const consent = (offers ) => `, series-wide ceiling: ${offers.join(', ') || 'no credentials'}; you explicitly consent to agents acting as you`;
410
+ const consent = (offers ) => `, series credentials: ${offers.join(', ') || 'no credentials'}; you explicitly consent to agents acting as you`;
351
411
 
352
412
  // Times as this machine's clock reads them, and lengths of time and costs, for the views.
353
413
  const when = (iso ) => new Date(iso).toLocaleString('sv-SE', { dateStyle: 'short', timeStyle: 'short' });
@@ -578,11 +638,22 @@ async function browserToken() {
578
638
  }
579
639
 
580
640
  if (cmd === 'login' && url) {
581
- token ??= await browserToken();
582
- const me = await get('/me');
583
- mkdirSync(dirname(config), { recursive: true });
584
- writeFileSync(config, JSON.stringify({ url, token }), { mode: 0o600 });
585
- console.log(`signed in as ${me.email}`);
641
+ if (auth === 'az') {
642
+ assertSafeAzUrl(url);
643
+ resource ||= process.env.RF_AZ_RESOURCE;
644
+ if (!resource) throw new Error('--az requires an explicit trusted --resource api://<app-id> (or RF_AZ_RESOURCE)');
645
+ assertValidAzResource(resource);
646
+ const me = await get('/me');
647
+ mkdirSync(dirname(config), { recursive: true });
648
+ writeFileSync(config, JSON.stringify({ url, auth: 'az', resource }), { mode: 0o600 });
649
+ console.log(`signed in as ${me.email} (az)`);
650
+ } else {
651
+ token ??= await browserToken();
652
+ const me = await get('/me');
653
+ mkdirSync(dirname(config), { recursive: true });
654
+ writeFileSync(config, JSON.stringify({ url, token }), { mode: 0o600 });
655
+ console.log(`signed in as ${me.email}`);
656
+ }
586
657
  } else if (cmd === 'ls' && !args.length) {
587
658
  // --mine: open instances of series you own.
588
659
  const me = flags.mine && await get('/me'), rows = (await get('/api')).flatMap(w => w.series.flatMap(s => [
@@ -596,8 +667,34 @@ if (cmd === 'login' && url) {
596
667
  for (const k of r.wakes) console.log(` wake ${k.id} ${k.at}${k.label ? ` starts ${k.label}` : ''}${k.days ? `, then each ${k.days.join(', ')}` : ''}${k.text ? `: ${k.text}` : ''}${k.check ? `; check ${k.check}${k.deadline ? ` until ${k.deadline}` : ''}${k.maxStaleMin ? `, max-stale ${k.maxStaleMin}m` : ''}${k.backstopHours ? `, backstop ${k.backstopHours}h` : ''}` : ''}`);
597
668
  }
598
669
  } else if (cmd === 'waiting' && !args.length) {
670
+ if (flags['dismiss-settled']) {
671
+ const res = await (await post('/api/messages', { dismissAll: 'settled' })).json();
672
+ console.log(flags.json ? JSON.stringify(res, null, 1) : `dismissed ${res.dismissed} settled note notice${res.dismissed === 1 ? '' : 's'}`);
673
+ } else {
599
674
  const [me, s, all] = await Promise.all([get('/me'), get('/api/status'), get('/api')]), mine = (who ) => (who ?? me.email) === me.email;
600
675
  const series = all.flatMap(w => w.series.map(x => ({ ...x, path: `${w.name}/${x.name}` })));
676
+ const refusedByHost = new Map ();
677
+ for (const w of all) if (!w.archived) for (const x of w.series) if (!x.archived) for (const i of x.instances) for (const r of i.refused ?? []) for (const h of r.hosts ?? []) {
678
+ const key = `${r.login}\0${r.site}\0${h}`, c = r.counts?.[h] ?? r.count ?? 1, hostAt = r.ats?.[h] ?? r.at ?? '', t = Date.parse(hostAt) || 0, rev = r.revs?.[h] ?? r.siteRev;
679
+ const prev = refusedByHost.get(key);
680
+ if (!prev) refusedByHost.set(key, { path: `${w.name}/${x.name}/${i.label}`, since: hostAt, t, run: r.run, site: r.site, ...(rev && { rev }), person: r.login, host: h, why: r.why?.[h] ?? '', count: c });
681
+ else {
682
+ prev.count += c;
683
+ if (t > prev.t || (t === prev.t && (r.run ?? 0) >= prev.run)) Object.assign(prev, { path: `${w.name}/${x.name}/${i.label}`, since: hostAt, t, run: r.run, ...(rev && { rev }), why: r.why?.[h] || prev.why });
684
+ }
685
+ }
686
+ const refusedRows = new Map ();
687
+ for (const h of refusedByHost.values()) {
688
+ const rowKey = `${h.person}\0${h.site}\0${h.path}\0${h.run}`;
689
+ let row = refusedRows.get(rowKey);
690
+ if (!row) refusedRows.set(rowKey, row = { path: h.path, since: h.since, t: h.t, run: h.run, site: h.site, person: h.person, hosts: [], why: {}, counts: {}, ats: {}, revs: {} });
691
+ else if (h.t > row.t) { row.since = h.since; row.t = h.t; }
692
+ row.hosts.push(h.host);
693
+ if (h.why) row.why[h.host] = h.why;
694
+ row.counts[h.host] = h.count;
695
+ if (h.since) row.ats[h.host] = h.since;
696
+ if (h.rev) row.revs[h.host] = h.rev;
697
+ }
601
698
  const rows = [
602
699
  ...s.ownership.map(s => ({ kind: 'owner', path: s.path, text: s.text })),
603
700
  ...s.asks.filter(a => a.who === me.email && !a.legacyNotice).map(a => ({ kind: a.note ? 'note' : 'ask', path: a.path, since: a.since, text: a.text })),
@@ -605,13 +702,15 @@ if (cmd === 'login' && url) {
605
702
  ...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 ${r.target ? 'wake' : 'start'} ${r.label}${r.text ? `: ${r.text}` : ''}` }))),
606
703
  ...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`}` })),
607
704
  ...s.expired.filter(e => e.who === me.email).map(e => ({ kind: 'expired', login: e.login, holding: e.holding, text: `your ${e.login} login expired` })),
608
- ...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(', ')}` })))),
705
+ ...[...refusedRows.values()].map(r => ({ kind: 'refused', path: r.path, since: r.since, site: r.site, hosts: r.hosts, person: r.person, why: r.why, counts: r.counts, ats: r.ats, ...(Object.keys(r.revs).length && { revs: r.revs }), text: `run ${r.run}'s browser on ${r.person}'s ${r.site} was refused ${r.hosts.map(h => { const c = r.counts[h]; const meta = [c > 1 ? `${c}×` : '', r.why[h] ?? ''].filter(Boolean).join(', '); return meta ? `${h} (${meta})` : h; }).join(', ')}` })),
706
+ ...all.filter(w => !w.archived).flatMap(w => w.series.filter(x => !x.archived).flatMap(x => x.instances.filter(i => i.wrong && i.owner === me.email).map(i => ({ kind: 'correction', path: `${w.name}/${x.name}/${i.label}`, since: i.active, count: i.wrong, text: `${i.wrong} correction${i.wrong === 1 ? '' : 's'} say${i.wrong === 1 ? 's' : ''} it's wrong` })))),
609
707
  ...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: grantText(g) }))),
610
708
  ];
611
709
  if (flags.json) console.log(JSON.stringify(rows, null, 1));
612
710
  else console.log(rows.map(r => r.kind === 'open' || r.kind === 'settled'
613
711
  ? `note ${r.kind} ${r.path}#${r.id} by ${r.by} at ${when(r.at)}: ${gist(r.text, 120)}`
614
712
  : `${r.kind} ${r.path ?? r.login}${r.since ? ` since ${when(r.since)}` : ''}${r.id ? `, ${r.kind === 'grant' ? 'grant' : 'request'} ${r.id}` : ''}: ${r.kind === 'grant' ? r.text : r.text.split('\n')[0].slice(0, 120)}`).join('\n') || 'Nothing waits on you.');
713
+ }
615
714
  } else if (cmd === 'show' && args.length === 1) {
616
715
  const { inst, at } = await instanceAt(args[0]), { doc, log, run, queued, owner, waiting: w } = await get(at);
617
716
  const waiting = w.map(({ who, seq }) => {
@@ -757,16 +856,43 @@ else if (cmd === 'comment' && args.length < 2) {
757
856
  else console.log(`${args[1]}: series owner ${s.owner ?? 'not selected'}`);
758
857
  } else if (cmd === 'series' && args[0] === 'credentials' && args.length === 2) {
759
858
  const s = await seriesAt(args[1]);
859
+ const fmtSched = (k ) => ` ${k.id} ${k.targetLabel ?? k.target} ${k.at}${k.deadline ? ` (deadline ${k.deadline})` : ''}${k.days ? ` (${k.days.join(',')})` : ''}${k.label ? ` ${k.label}` : ''}${k.from ? ` by ${k.from}` : ''}${k.check ? ` check=${k.check}` : ''}${k.text ? ` ${k.text}` : ''}`;
760
860
  if (flags.set !== undefined || flags.clear) {
761
861
  if (!['true', 'false'].includes(String(flags.autonomous))) throw new Error('saving requires --autonomous true|false');
762
- await post(`/api/series/${s.id}/credentials`, { logins: ticks(), autonomous: flags.autonomous === 'true' }, 'PUT');
862
+ const previewRes = await api(`/api/series/${s.id}/credentials`, {}, flags.autonomous === 'true' ? [] : [404, 405]);
863
+ const preview = previewRes.ok ? await previewRes.json() : null;
864
+ if (flags.autonomous === 'true' && !preview) {
865
+ throw new Error('could not load pending schedules to review before enabling autonomous runs');
866
+ }
867
+ if (flags.autonomous === 'true' && Array.isArray(preview?.schedules) && preview.schedules.length) {
868
+ console.log(`pending schedules to be adopted (${preview.schedules.length}):`);
869
+ for (const k of preview.schedules) console.log(fmtSched(k));
870
+ }
871
+ const body = { logins: ticks(), autonomous: flags.autonomous === 'true' };
872
+ if (preview?.epoch !== undefined) body.expectedEpoch = preview.epoch;
873
+ if (preview?.scheduleRevision) body.expectedSchedules = preview.scheduleRevision;
874
+ const putRes = await post(`/api/series/${s.id}/credentials`, body, 'PUT');
875
+ const rawText = await putRes.text();
876
+ let saved = null;
877
+ try { saved = JSON.parse(rawText); } catch {}
763
878
  console.log(`saved ${args[1]}${consent(ticks())}; autonomous ${flags.autonomous}`);
879
+ if (!preview && flags.autonomous === 'true' && Array.isArray(saved?.schedules) && saved.schedules.length) {
880
+ console.log(`pending schedules that will run (${saved.schedules.length}):`);
881
+ for (const k of saved.schedules) console.log(fmtSched(k));
882
+ }
764
883
  } else {
765
884
  if (flags.autonomous !== undefined) throw new Error('select credentials with --set OFFER,... or --clear');
766
885
  const mine = await get('/logins');
767
- const out = { owner: s.owner, consent: s.consent, yours: mine.flatMap(l => l.offers.map(o => ({ ...o, ...(l.expired && { expired: true }) }))) };
886
+ const detail = await api(`/api/series/${s.id}/credentials`, {}, [404, 405]).then(async r => r.ok ? r.json() : null).catch(() => null);
887
+ const out = { owner: s.owner, consent: s.consent, schedules: detail?.schedules ?? [], yours: mine.flatMap((l ) => l.offers.map((o ) => ({ ...o, ...(l.expired && { expired: true }) }))) };
768
888
  if (flags.json) console.log(JSON.stringify(out, null, 1));
769
- else console.log([`Series owner: ${out.owner ?? 'not selected'}`, out.consent ? `Series-wide ceiling: ${out.consent.logins.join(', ') || 'no credentials'}; autonomous ${out.consent.autonomous}` : 'No execution consent', 'your offers:', ...out.yours.map(o => ` ${o.id} ${o.name}${o.expired ? ' expired' : ''}`)].join('\n'));
889
+ else console.log([
890
+ `Series owner: ${out.owner ?? 'not selected'}`,
891
+ out.consent ? `Series credentials: ${out.consent.logins.join(', ') || 'no credentials'}; autonomous ${out.consent.autonomous}` : 'No execution consent',
892
+ ...(out.schedules.length ? [`pending schedules (${out.schedules.length}):`, ...out.schedules.map(fmtSched)] : []),
893
+ 'your offers:',
894
+ ...out.yours.map((o ) => ` ${o.id} ${o.name}${o.expired ? ' expired' : ''}`),
895
+ ].join('\n'));
770
896
  }
771
897
  } else if (cmd === 'rename' && args.length === 2) {
772
898
  const [w, s, l] = args[0].replace(/\/+$/, '').split('/');
@@ -794,7 +920,7 @@ else if (cmd === 'comment' && args.length < 2) {
794
920
  if (flags.creds !== undefined || flags.clear || flags.autonomous !== undefined) throw new Error('instance credentials were removed: use rf series credentials SERIES');
795
921
  const series = await seriesAt(args[1]);
796
922
  const { id } = await (await post(`/api/series/${series.id}`, { label: args[2], quiet: !flags.wake })).json();
797
- console.log(`made ${await pathOf(id)}; series owner and ceiling unchanged${series.owner ? `; ${series.owner} starts its runs` : ''}`);
923
+ console.log(`made ${await pathOf(id)}; series owner and credentials unchanged${series.owner ? `; ${series.owner} starts its runs` : ''}`);
798
924
  } else if (cmd === 'new' && args[0] === 'series' && args.length === 3) {
799
925
  await post(`/api/series/${(await find(args[1])).series.id}/promote`, { name: args[2] });
800
926
  console.log(`made the series ${args[1].split('/')[0]}/${args[2]}`);
@@ -813,7 +939,7 @@ else if (cmd === 'comment' && args.length < 2) {
813
939
  if (flags.creds !== undefined || flags.clear) throw new Error('request credentials were removed: use rf series credentials SERIES');
814
940
  const r = await post(`/api/requests/${args[1]}`, { quiet: !flags.wake });
815
941
  const woke = r.headers.get('X-RF-Woke') === '1', { id } = await r.json();
816
- console.log(`${woke ? 'woke' : 'made'} ${await pathOf(id)}; series owner and ceiling unchanged`);
942
+ console.log(`${woke ? 'woke' : 'made'} ${await pathOf(id)}; series owner and credentials unchanged`);
817
943
  }
818
944
  } else if (cmd === 'logins' && !args.length) {
819
945
  const all = await get('/logins');
@@ -823,13 +949,17 @@ else if (cmd === 'comment' && args.length < 2) {
823
949
  // A website's login offers itself alone.
824
950
  for (const o of l.offers.filter(o => o.id !== l.id)) console.log(` offers ${o.id} ${o.name}`);
825
951
  }
826
- } else if (cmd === 'logins' && ['offer', 'unoffer', 'allow', 'disallow'].includes(args[0]) && args.length === 3) {
952
+ } else if (cmd === 'logins' && ['offer', 'unoffer', 'allow', 'refuse', 'disallow'].includes(args[0]) && args.length === 3) {
827
953
  const [what, login, x] = args, at = `/logins/${encodeURIComponent(login)}`;
828
954
  if (what === 'offer') await post(`${at}/offers`, { add: x });
829
955
  else if (what === 'unoffer') await api(`${at}/offers/${encodeURIComponent(x)}`, { method: 'DELETE' });
830
956
  else if (what === 'disallow') await api(`/logins/web/${encodeURIComponent(login)}/hosts/${encodeURIComponent(x)}`, { method: 'DELETE' });
831
- else await post(`/logins/web/${encodeURIComponent(login)}/hosts${flags.person ? `?person=${encodeURIComponent(String(flags.person))}` : ''}`, { host: x });
832
- console.log(`${login} ${{ offer: 'offers', unoffer: 'no longer offers', allow: 'reaches', disallow: 'no longer reaches' }[what]} ${x}`);
957
+ else if (what === 'refuse' || what === 'allow') {
958
+ if (flags.rev !== undefined && !String(flags.rev).trim()) throw new Error('--rev: site revision cannot be empty');
959
+ const rev = flags.rev !== undefined ? { siteRev: String(flags.rev) } : {};
960
+ await post(`/logins/web/${encodeURIComponent(login)}/hosts${flags.person ? `?person=${encodeURIComponent(String(flags.person))}` : ''}`, { host: x, ...(what === 'refuse' && { allow: false }), ...rev });
961
+ }
962
+ console.log(what === 'refuse' ? `${login} keeps ${x} blocked` : `${login} ${{ offer: 'offers', unoffer: 'no longer offers', allow: 'reaches', disallow: 'no longer reaches' }[what]} ${x}`);
833
963
  } else if (cmd === 'vpns' && !args.length) {
834
964
  const all = await get('/vpns');
835
965
  if (flags.json) console.log(JSON.stringify(all, null, 1));