@rfany/rf 0.21.0 → 0.21.1
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 +32 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfany/rf",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.1",
|
|
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
|
@@ -385,15 +385,16 @@ Sign in to a VPN on the page. VPN access needs an explicit grant, even for admin
|
|
|
385
385
|
|
|
386
386
|
async function find(path ) {
|
|
387
387
|
const [w, s, l, more] = path.replace(/\/+$/, '').split('/');
|
|
388
|
-
const
|
|
388
|
+
const ws = s !== undefined && more === undefined ? (await get('/api')).find(x => x.name === w) : undefined;
|
|
389
|
+
const series = ws?.series.find(x => x.name === s);
|
|
389
390
|
const inst = l === undefined ? undefined : series?.instances.find(i => i.label === l);
|
|
390
391
|
if (!series || (l !== undefined && !inst)) throw new Error(`nothing you can see at ${path}`);
|
|
391
|
-
return { series, inst, at: inst ? `/api/instances/${inst.id}` : '' };
|
|
392
|
+
return { ws, series, inst, at: inst ? `/api/instances/${inst.id}` : '' };
|
|
392
393
|
}
|
|
393
394
|
async function instanceAt(path ) {
|
|
394
|
-
const { series, inst, at } = await find(path);
|
|
395
|
+
const { ws, series, inst, at } = await find(path);
|
|
395
396
|
if (!inst) throw new Error(`${path} is a series: name one of its instances, as rf ls lists them`);
|
|
396
|
-
return { series, inst, at };
|
|
397
|
+
return { ws, series, inst, at };
|
|
397
398
|
}
|
|
398
399
|
async function seriesAt(path ) {
|
|
399
400
|
const { series, inst } = await find(path);
|
|
@@ -407,6 +408,7 @@ async function workspaceNamed(name ) {
|
|
|
407
408
|
}
|
|
408
409
|
// An instance's path as rf ls prints it, by its id.
|
|
409
410
|
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];
|
|
411
|
+
const shQuote = (s ) => `'${s.replace(/'/g, `'\\''`)}'`;
|
|
410
412
|
// Explicit series-wide offer selection.
|
|
411
413
|
const ticks = () => flags.clear ? [] : String(flags.creds ?? flags.set ?? '').split(',').map(o => o.trim()).filter(Boolean);
|
|
412
414
|
const consent = (offers ) => `, series credentials: ${offers.join(', ') || 'no credentials'}; you explicitly consent to agents acting as you`;
|
|
@@ -694,15 +696,27 @@ if (cmd === 'login' && url) {
|
|
|
694
696
|
? `note ${r.kind} ${r.path}#${r.id} by ${r.by} at ${when(r.at)}: ${gist(r.text, 120)}`
|
|
695
697
|
: `${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.');
|
|
696
698
|
} else if (cmd === 'show' && args.length === 1) {
|
|
697
|
-
const { inst, at } = await instanceAt(args[0]), { doc, log, run, queued, owner, waiting: w } = await get(at);
|
|
699
|
+
const { ws, series, inst, at } = await instanceAt(args[0]), { doc, log, run, queued, owner, waiting: w } = await get(at);
|
|
698
700
|
const waiting = w.map(({ who, seq }) => {
|
|
699
701
|
const e = log[seq - 1], first = log.find(x => `c${x.seq}` === e.thread);
|
|
700
702
|
return { comment: `c${seq}`, thread: e.thread, kind: e.ask === true ? 'ask' : e.ask ?? 'note', for: who, by: e.by, item: first.item, ref: first.ref, text: e.text };
|
|
701
703
|
});
|
|
702
704
|
const done = log.findLast(e => e.op === 'done'), last = done ? { run: done.run, cost: done.cost, ...(done.estimated && { estimated: true }), error: done.error ?? null } : null;
|
|
703
|
-
|
|
705
|
+
const seriesPath = args[0].replace(/\/+$/, '').split('/').slice(0, 2).join('/');
|
|
706
|
+
if (flags.json) console.log(JSON.stringify({ path: args[0], id: inst.id, status: doc.status, owner: owner.by, consent: !!owner.consent, running: run, queued, items: doc.items, waiting, last_run: last, ...(doc.status === 'deleted' && { deleted: { by: log[0].by, at: log[0].at } }) }, null, 1));
|
|
704
707
|
else {
|
|
705
|
-
|
|
708
|
+
let noConsent = '';
|
|
709
|
+
if (doc.status === 'open' && !ws?.archived && !series.archived && !owner.consent) {
|
|
710
|
+
if (!owner.by) noConsent = ', no series owner';
|
|
711
|
+
else {
|
|
712
|
+
const me = await get('/me');
|
|
713
|
+
noConsent = me.email === owner.by
|
|
714
|
+
? `, no execution consent (run: rf series credentials ${shQuote(seriesPath)})`
|
|
715
|
+
: `, no execution consent (${owner.by} must select series credentials)`;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const ownerLabel = owner.by ? `series owner ${owner.by}` : 'no series owner';
|
|
719
|
+
console.log(doc.status === 'deleted' ? `${args[0]} deleted by ${log[0].by} ${when(log[0].at)}` : `${args[0]} ${doc.status}, ${ownerLabel}${owner.by ? noConsent : ''}${run ? `, run ${run.n} going, ${usdNote(run.cost, run.estimated)}` : queued ? ', queued' : ''}`);
|
|
706
720
|
for (const i of doc.items) console.log(` ${i.kind.padEnd(6)} ${i.id} ${i.name} ${i.file ?? 'no file yet'}${i.from?.length ? ` from ${i.from.join(', ')}` : ''}${i.headline ? ` ${i.headline}` : ''}`);
|
|
707
721
|
for (const w of waiting) console.log(`${w.comment} ${w.kind} for ${w.for}${w.comment === w.thread ? '' : ` in ${w.thread}`}${w.item ? `, on ${w.item}${w.ref ? ` at ${w.ref}` : ''}` : ''}: ${w.text.split('\n')[0].slice(0, 160)}`);
|
|
708
722
|
if (last) console.log(`last run ${last.run} ${usdNote(last.cost ?? 0, last.estimated)}${last.error ? ` ${last.error}` : ''}`);
|
|
@@ -767,7 +781,17 @@ else if (cmd === 'comment' && args.length < 2) {
|
|
|
767
781
|
if (!inst) console.log(`noted ${(await posted.json()).id} on ${path}: it starts no run, and its runs read it`);
|
|
768
782
|
else {
|
|
769
783
|
const seq = Number(posted.headers.get('X-RF-Comment-Seq')), { doc, log, owner, starts, standing } = await get(at), note = log.find(e => e.seq === seq)?.note;
|
|
770
|
-
if (!starts && standing?.[seq] !== 'answer')
|
|
784
|
+
if (!starts && standing?.[seq] !== 'answer') {
|
|
785
|
+
if (!owner.consent) {
|
|
786
|
+
if (!owner.by) console.log(`kept as a note, seq ${seq}: no run starts because this series has no owner`);
|
|
787
|
+
else {
|
|
788
|
+
const [me, livePath] = await Promise.all([get('/me'), pathOf(inst.id)]);
|
|
789
|
+
const seriesPath = (livePath ?? path).replace(/\/+$/, '').split('/').slice(0, 2).join('/');
|
|
790
|
+
if (me.email === owner.by) console.log(`kept as a note, seq ${seq}: no run starts because you have no execution consent on this series (run: rf series credentials ${shQuote(seriesPath)})`);
|
|
791
|
+
else console.log(`recorded for the series owner, ${owner.by}, seq ${seq}: no run starts until ${owner.by} selects series credentials`);
|
|
792
|
+
}
|
|
793
|
+
} else console.log(`recorded for the series owner, ${owner.by}, seq ${seq}: no run starts`);
|
|
794
|
+
}
|
|
771
795
|
else if (!wait) console.log(`${note ? `a note for the series owner, ${owner.by}` : 'commented'}, seq ${seq}`);
|
|
772
796
|
else if (doc.status !== 'open') console.log(`The instance was ${doc.status}.`);
|
|
773
797
|
else for (;;) {
|