@rfany/rf 0.20.2 → 0.20.3
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 +53 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rfany/rf",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
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,8 @@
|
|
|
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 {
|
|
4
|
+
import { randomBytes } from 'node:crypto';
|
|
5
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, utimesSync, writeFileSync, } from 'node:fs';
|
|
5
6
|
import { spawn } from 'node:child_process';
|
|
6
7
|
import { homedir, hostname } from 'node:os';
|
|
7
8
|
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
@@ -49,9 +50,9 @@ rf approve PATH cN [TEXT] [--wake] records content approval of proposal cN, no
|
|
|
49
50
|
rf reject PATH cN [TEXT] [--wake] rejects the agent's proposal cN, with feedback on missing information or changes;
|
|
50
51
|
revised work takes a new proposal
|
|
51
52
|
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
|
|
52
|
-
rf close PATH [--as-series NAME]
|
|
53
|
+
rf close PATH [--as-series NAME] the series owner makes it the record and an example,
|
|
53
54
|
approving nothing; a task closes as a one-off, or as the first instance of the series NAME it
|
|
54
|
-
becomes
|
|
55
|
+
becomes
|
|
55
56
|
rf abandon PATH the series owner leaves it as it is, neither an example nor a starting point
|
|
56
57
|
rf delete PATH [--yes] its workspace's owners and admins delete an instance, in any status, once they confirm, or
|
|
57
58
|
with --yes: a run for it is cut, and all the server holds of it goes but its label and place,
|
|
@@ -105,12 +106,14 @@ rf grant approve|deny ID [TEXT] a request to use a website in a workspace you
|
|
|
105
106
|
rf grant revoke ID a grant pending or approved, yours or in a workspace you own; its runs' browsers close
|
|
106
107
|
rf correct PATH TEXT [--item ID] [--ref REF] [--superseded] [--see LABEL] a closed instance, or its item ID at REF, is
|
|
107
108
|
wrong, or superseded, as LABEL, another instance of its series, shows; it can't be withdrawn
|
|
108
|
-
rf wake PATH AT [TEXT] [--label LABEL] [--days DAYS] [--check PATH [--deadline ISO]] | rf wake --cancel ID
|
|
109
|
+
rf wake PATH AT [TEXT] [--label LABEL] [--days DAYS] [--check PATH [--deadline ISO] [--max-stale MIN] [--backstop-hours H]] | rf wake --cancel ID
|
|
109
110
|
AT now, +<n>m|h|d or a date; PATH an open instance, or a series with LABEL; TEXT a short
|
|
110
111
|
message for the run; the owner's now starts under current consent without autonomous opt-in;
|
|
111
112
|
later or agent-set wakes need it. Collaborators' wakes are requests. DAYS, such as mon-fri,
|
|
112
113
|
repeats weekly at AT's time. With the owner's wake-check capability, --check working/FILE.py (or .ts)
|
|
113
|
-
gates a scheduled wake; optional --deadline TIME (ISO with offset) runs Pi even if the check stops
|
|
114
|
+
gates a scheduled wake; optional --deadline TIME (ISO with offset) runs Pi even if the check stops,
|
|
115
|
+
--max-stale MIN overrides the 150m M365 index staleness cap, and --backstop-hours H overrides the
|
|
116
|
+
24h recurring skip backstop.
|
|
114
117
|
rf agents [WORKSPACE] [--set FILE|-] the company's AGENTS.md, or a workspace's; setting the company's is for admins
|
|
115
118
|
rf readers WORKSPACE [add|remove OTHER] the workspaces whose agents read WORKSPACE and those its own read, as each one's
|
|
116
119
|
owners let them; its owners let OTHER's agents read it, one they see, and its owners or
|
|
@@ -187,7 +190,7 @@ What there is
|
|
|
187
190
|
credentials. Scheduled and autonomous runs need a separate opt-in. Other collaborators' comments, uploads and approvals are notes that start nothing.
|
|
188
191
|
Transferring the whole series stops old runs and clears consent; old unread instructions become notes. Each act keeps
|
|
189
192
|
its author, and every run its executor.
|
|
190
|
-
- rf is quiet: a comment, upload, approval, rejection,
|
|
193
|
+
- rf is quiet: a comment, upload, approval, rejection, new instance or request it starts begins no run unless --wake, and the agent
|
|
191
194
|
reads it at its next run. The owner's rf wake PATH now starts one under current consent, without autonomous opt-in.
|
|
192
195
|
A quiet upload or comment is committed to the instance's history at once.
|
|
193
196
|
- 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
|
|
@@ -406,24 +409,52 @@ const runsIn = async (path = '') => (await get(`/api/runs?since=${since}`))
|
|
|
406
409
|
.filter(r => !path || r.path === path.replace(/\/+$/, '') || r.path.startsWith(path.replace(/\/+$/, '') + '/'));
|
|
407
410
|
|
|
408
411
|
function write(path , data , mtime ) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
412
|
+
const dir = dirname(path);
|
|
413
|
+
mkdirSync(dir, { recursive: true });
|
|
414
|
+
const existing = lstatSync(path, { throwIfNoEntry: false });
|
|
415
|
+
if (existing?.isSymbolicLink()) throw new Error(`${path} is a symlink: remove it or pull into another directory`);
|
|
416
|
+
const tmp = join(dir, `.rf-pull-${process.pid}-${randomBytes(6).toString('hex')}.tmp`);
|
|
417
|
+
try {
|
|
418
|
+
writeFileSync(tmp, data, { flag: 'wx', mode: 0o600 });
|
|
419
|
+
utimesSync(tmp, new Date(mtime), new Date(mtime));
|
|
420
|
+
chmodSync(tmp, 0o444);
|
|
421
|
+
try {
|
|
422
|
+
renameSync(tmp, path);
|
|
423
|
+
} catch (e) {
|
|
424
|
+
const code = (e ).code;
|
|
425
|
+
if (process.platform === 'win32' && (code === 'EPERM' || code === 'EACCES')) {
|
|
426
|
+
const cur = lstatSync(path, { throwIfNoEntry: false });
|
|
427
|
+
if (cur && !cur.isSymbolicLink() && cur.isFile()) {
|
|
428
|
+
const oldMode = cur.mode;
|
|
429
|
+
chmodSync(path, 0o644);
|
|
430
|
+
try {
|
|
431
|
+
renameSync(tmp, path);
|
|
432
|
+
} catch (retryErr) {
|
|
433
|
+
try { chmodSync(path, oldMode); } catch {}
|
|
434
|
+
throw retryErr;
|
|
435
|
+
}
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
throw e;
|
|
440
|
+
}
|
|
441
|
+
} catch (e) {
|
|
442
|
+
rmSync(tmp, { force: true });
|
|
443
|
+
throw e;
|
|
444
|
+
}
|
|
414
445
|
}
|
|
415
446
|
|
|
416
447
|
// 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
|
|
417
448
|
// 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
|
|
418
449
|
// in a dot or a space, which Windows drops. Nor may a name be what git takes for a .git, such as .GIT on a disk that ignores case,
|
|
419
|
-
// whose config would run a command as git runs there. A link where one of its folders goes, or `base`,
|
|
420
|
-
// elsewhere too, and is refused.
|
|
450
|
+
// whose config would run a command as git runs there. A link where one of its folders goes, or `base`, or at the file itself,
|
|
451
|
+
// would take the file elsewhere too, and is refused.
|
|
421
452
|
const under = (base , rel ) => {
|
|
422
453
|
const names = rel.split('/');
|
|
423
454
|
if (names.some(n => !n || n === '.' || n === '..' || basename(n) !== n || /^(\.git|git~1)[. ]*([:\\]|$)/i.test(n)
|
|
424
455
|
|| (process.platform === 'win32' && (/[<>:"|?*\x00-\x1f]|[. ]$/.test(n) || /^(con|prn|aux|nul|com\d|lpt\d)(\.|$)/i.test(n))))) return undefined;
|
|
425
456
|
let folder = base;
|
|
426
|
-
for (const name of ['', ...names
|
|
457
|
+
for (const name of ['', ...names]) {
|
|
427
458
|
folder = join(folder, name);
|
|
428
459
|
let st ;
|
|
429
460
|
try { st = lstatSync(folder, { throwIfNoEntry: false }); }
|
|
@@ -562,7 +593,7 @@ if (cmd === 'login' && url) {
|
|
|
562
593
|
else for (const r of rows) {
|
|
563
594
|
console.log(r.deleted ? `${r.path} deleted by ${r.deleted.by} ${when(r.deleted.at)}` : r.status ? `${r.path} ${r.status}${r.running ? ', running' : ''}${r.asks ? `, ${r.asks} asks waiting` : ''}, owner ${r.owner}` : `${r.path}${r.requests ? ` ${r.requests} asking to start` : ''}`);
|
|
564
595
|
if (r.wakeCheck) console.log(` Wake check stopped: ${clip(r.wakeCheck.message.replace(/[\x00-\x1f\x7f-\x9f]/g, ' '), TEXT_COLS)}`);
|
|
565
|
-
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}` : ''}` : ''}`);
|
|
596
|
+
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` : ''}` : ''}`);
|
|
566
597
|
}
|
|
567
598
|
} else if (cmd === 'waiting' && !args.length) {
|
|
568
599
|
const [me, s, all] = await Promise.all([get('/me'), get('/api/status'), get('/api')]), mine = (who ) => (who ?? me.email) === me.email;
|
|
@@ -857,8 +888,12 @@ else if (cmd === 'comment' && args.length < 2) {
|
|
|
857
888
|
} else if (cmd === 'wake' && [2, 3].includes(args.length)) {
|
|
858
889
|
const { series, inst } = await find(args[0]);
|
|
859
890
|
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]);
|
|
860
|
-
const
|
|
861
|
-
|
|
891
|
+
const num = (v ) => (typeof v !== 'string' ? undefined : /^\d+$/.test(v) ? Number(v) : v);
|
|
892
|
+
const w = await (await post(`/api/wakes/${inst?.id ?? series.id}`, {
|
|
893
|
+
at: new Date(at).toISOString(), label: flags.label, days: flags.days, text: args[2], check: flags.check, deadline: flags.deadline,
|
|
894
|
+
maxStaleMin: num(flags['max-stale']), backstopHours: num(flags['backstop-hours']),
|
|
895
|
+
}, 'PUT')).json();
|
|
896
|
+
console.log(`wake ${w.id} at ${w.at}${w.days ? `, then each ${w.days.join(', ')}` : ''}${w.check ? `; check ${w.check}${w.deadline ? ` until ${w.deadline}` : ''}${w.maxStaleMin ? `, max-stale ${w.maxStaleMin}m` : ''}${w.backstopHours ? `, backstop ${w.backstopHours}h` : ''}` : ''}`);
|
|
862
897
|
} else if (cmd === 'agents' && args.length <= 1) {
|
|
863
898
|
const ws = args[0] === undefined ? undefined : await workspaceNamed(args[0]);
|
|
864
899
|
if (typeof flags.set !== 'string') console.log(ws ? ws.agents : (await get('/agents')).text);
|
|
@@ -1064,7 +1099,7 @@ else if (cmd === 'kill' && args.length === 1 && /^\d+$/.test(args[0])) {
|
|
|
1064
1099
|
if (flags.json) console.log(JSON.stringify(rows, null, 1));
|
|
1065
1100
|
else for (const r of rows) {
|
|
1066
1101
|
console.log(`${r.path} last woken ${r.fired ? when(r.fired) : 'never'}${r.wakes.length || r.requests.length ? '' : ', none pending'}`);
|
|
1067
|
-
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}${k.text ? `: ${k.text}` : ''}${k.check ? `; check ${k.check}${k.deadline ? ` until ${k.deadline}` : ''}` : ''}`);
|
|
1102
|
+
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}${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` : ''}` : ''}`);
|
|
1068
1103
|
for (const q of r.requests) console.log(` request ${q.id} to ${q.target ? 'wake' : 'start'} ${q.label}, from ${q.from} since ${when(q.at)}, waits on ${q.who ?? 'anyone'}${q.text ? `: ${q.text}` : ''}`);
|
|
1069
1104
|
}
|
|
1070
1105
|
} else if (cmd === 'activity' && args.length <= 1) {
|