@rfany/rf 0.6.0 → 0.9.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/rf.mjs +85 -30
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rfany/rf",
3
- "version": "0.6.0",
3
+ "version": "0.9.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
@@ -14,12 +14,18 @@ rf pull PATH DIR [--delete] [-n|--dry-run] [--exclude PATTERN]...
14
14
  rf help how rollforward works and how to use rf, for an agent
15
15
  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
16
  rf upload PATH FILE [--onto ITEM] [--output]
17
- rf wake PATH AT REASON [--label LABEL] AT now, +<n>m|h|d or a date; PATH an open instance, or a series with LABEL
17
+ rf wake PATH AT [--label LABEL] [--days DAYS] | rf wake --cancel ID
18
+ AT now, +<n>m|h|d or a date; PATH an open instance, or a series with LABEL; DAYS, such as
19
+ mon-fri, repeats it weekly at AT's time; rf ls shows each wake's ID
18
20
  rf agents [WORKSPACE] [--set FILE|-] the company's AGENTS.md, or a workspace's; setting the company's is for admins
19
21
  rf skills
20
- rf websites
22
+ rf skill pull ID [DIR] [--version N] the newest version, or N, into DIR, ./ID by default, new or empty, as push reads it
23
+ rf skill versions ID
24
+ rf connections
21
25
  rf status [--long MIN] [--json] what goes on and what's stuck: runs going, flagged past MIN minutes (30), and queued, with why;
22
26
  what waits on whom since when; open instances whose last run failed
27
+ rf indexes [--json] each index of a source you index, all for admins: its kind, items and size, and per person
28
+ its phase, crawl or follow, pages read, when last caught up, and its error and next try
23
29
  rf runs [PATH] [--since DATE] [--failed] [--running] [--long MIN] [--json]
24
30
  a line per run: start, path, run, outcome, time, cost, what started it, summary or error
25
31
  rf costs [PATH] [--since DATE] [--by workspace|series|person|day] [--json] totals, runs and cost per run; person is the runner
@@ -27,21 +33,31 @@ rf people WORKSPACE [--set FILE|-] [-n] [--force] its owners and admins: its p
27
33
  each with a comment; --set replaces them, -n shows the changes, --force hides open instances
28
34
  from their runners
29
35
 
30
- Publishers and admins:
36
+ Admins, and those they grant publish:
31
37
  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
38
  rf skill rollback ID N pushes version N again, as the newest
34
39
 
35
40
  Admins:
36
41
  rf people [--set FILE|-] [-n] [--force] everyone as lines of ROLE EMAIL, each with a comment; --set sets the roles of the people
37
42
  listed and adds new ones, removing no one
38
- rf user add EMAIL [admin|publisher] | role EMAIL admin|publisher|user [--force] | disable EMAIL | enable EMAIL | signout EMAIL | remove EMAIL
39
- rf website set ID URL [--name NAME] [--hosts HOST,...] a website people sign in to at URL, and the other hosts its pages need,
40
- such as sso.example.com or *.example.com; a run's browser on it reaches only those
41
- rf website remove ID
43
+ rf user add EMAIL [admin] | role EMAIL admin|user [--force] | disable EMAIL | enable EMAIL | signout EMAIL | remove EMAIL
44
+ rf connection set NAME TYPE [--SETTING VALUE]... an outside system runs reach as their runner, by a login each person makes:
45
+ graph, Microsoft 365, with no settings; databricks, --host HOST --warehouse ID, a workspace
46
+ and its SQL warehouse; website, --url URL [--hosts HOST,...] [--title TITLE] [--writeback
47
+ false] [--header NAME] [--keepalive PAGE --every 10m [--hours 08:00-19:00]] [--people
48
+ EMAIL|GROUP,...], where people sign in, the other hosts its pages need, such as
49
+ *.example.com, whether a run's browser writes its state back, a header its sign-in needs
50
+ that its pages never send, such as x-bot-token, whose value each person gives, a page, by
51
+ its address or path, such as https://patriarch.patrina.net/PatriArchMVC/, to load in each
52
+ live login's browser every so often, in office hours on weekdays if given, so idle sessions
53
+ stay alive, and who alone may use it, by email or Entra group id
54
+ rf connection remove NAME
42
55
  rf brand [--text TEXT] [--logo FILE] [--clear] the deployment's text and logo, a .png, .jpg, .gif, .webp or .svg, which top
43
56
  the sidebar and are the page's title and icon; --clear goes back to the plain look, and with
44
- no option it prints them`;
57
+ no option it prints them
58
+ rf can [CAP [EMAIL|GROUP,...] [--clear]] what users may do beyond the rest, as admins may: publish, push skills, and
59
+ create, make workspaces; a list grants CAP to those emails and Entra group ids in place of
60
+ whom it had, --clear to no one, and with neither it prints whom each is granted to`;
45
61
 
46
62
  const GUIDE = `rollforward runs a team's recurring work, such as a weekly borrowing base or a month-end reconciliation, with an agent
47
63
  that does each period's work and people who check it. rf does what its page does, as you.
@@ -61,30 +77,37 @@ What there is
61
77
  What rf pull copies, the folders as the agent sees them
62
78
  AGENTS.md the company's conventions; <workspace>/AGENTS.md the workspace's
63
79
  <workspace>/<series>/<label>/
64
- workspace.json the screen: {rev, status, items: [{id, name, kind, file, from, headline, source}]}
80
+ screen.json the screen: {rev, status, items: [{id, name, kind, file, from, headline, source}]}
65
81
  log.jsonl every event, by seq: by is a person's email, "server" or "agent"; op is upload, comment (thread, item,
66
82
  ref, text, ask, to, signoff), resolve, signoff (the runner's answer, with its commit), commit, point and
67
83
  item (the screen changing), run, report (the agent's account of a run), done (its cost, summary or
68
84
  error), close, and the rest
69
85
  upload/ what people uploaded, their comments' attachments in upload/attachments/
70
86
  working/ what the agent made, its scripts, and process.md, how it does this series
71
- session/ the agent's own session: every message and tool call of every run
87
+ session/ each run's session: every message and tool call of it
72
88
  browser/ each run's browser requests, and its screenshots
89
+ skills/ the skills the latest run loaded
90
+ names.tsv each instance in the latest run's reach, id<TAB>/work/<workspace>/<series>/<label>: names can
91
+ change, so where a path in a file doesn't match, look its id up in the names.tsv of the commit
92
+ that last changed the file (git log -1 -- FILE, then git show H:names.tsv), and its name now in
93
+ rf ls
73
94
  The copy is read-only, and only rf changes what's on the server: comment, upload and wake.
74
95
 
75
96
  Usual work
76
97
  - What waits on me: rf ls, then the asks in that instance's log.jsonl, ask true, whose thread has nothing after them.
77
98
  - Answer an ask: rf comment PATH TEXT --thread T --wait, which prints what the agent says back.
78
99
  - Give an input or a corrected output: rf upload PATH FILE [--onto ITEM] [--output].
79
- - Start an instance: rf wake SERIES now REASON --label LABEL, which starts it as whoever shares the series, else asks on the page for
80
- someone to start it; take one you run up later: rf wake PATH +2h REASON.
100
+ - Start an instance: rf wake SERIES now --label LABEL, which starts it as whoever shares the series, else asks on the page for
101
+ someone to start it; take one you run up later: rf wake PATH +2h.
81
102
  - 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
82
103
  every step.
83
104
 
84
105
  Watching over it, for admins and power users; each sees what the caller sees, and takes --json
85
106
  - What's stuck: rf status lists runs going, flagging those past --long MIN (30); queued runs, since when and why: their series is
86
107
  running, the RF_MAX_RUNS cap, or memory; what waits on whom since when: asks, notes for runners, expired logins and the instances
87
- they hold, and requests to start; and open instances whose last run failed.
108
+ they hold, and requests to start; open instances whose last run failed; and indexes crawling or failing.
109
+ - Indexes: rf indexes shows each index of a big library or mailbox you index, every one for admins: its items and size, and per
110
+ person whether it is crawling or following changes, pages read, when last caught up, and an error, if any, with its next try.
88
111
  - History: rf runs [PATH] [--since DATE] [--failed] [--running] [--long MIN] prints a line per run: its start, path, run number,
89
112
  outcome, time taken, cost, what started it and by whom, and its summary or error. rf costs [PATH] [--since DATE] [--by
90
113
  workspace|series|person|day] totals them, by the runner for person.
@@ -228,9 +251,16 @@ if (cmd === 'login' && url) {
228
251
  writeFileSync(config, JSON.stringify({ url, token }), { mode: 0o600 });
229
252
  console.log(`signed in as ${me.email}`);
230
253
  } else if (cmd === 'ls') {
254
+ const wakes = (list ) => {
255
+ for (const k of list) console.log(` wake ${k.id} ${k.at}${k.label ? ` starts ${k.label}` : ''}${k.days ? `, then each ${k.days.join(', ')}` : ''}`);
256
+ };
231
257
  for (const w of await get('/api')) for (const s of w.series) {
232
- console.log(`${w.name}/${s.name}${s.wake ? ` wakes ${s.wake.at} to start ${s.wake.label}: ${s.wake.reason}` : ''}${s.requests.length ? ` ${s.requests.length} asking to start` : ''}`);
233
- for (const i of s.instances) console.log(`${w.name}/${s.name}/${i.label} ${i.status}${i.running ? ', running' : ''}${i.asks.length ? `, ${i.asks.length} asks waiting` : ''}${i.wake ? `, wakes ${i.wake}` : ''}, runner ${i.runner}`);
258
+ console.log(`${w.name}/${s.name}${s.requests.length ? ` ${s.requests.length} asking to start` : ''}`);
259
+ wakes(s.wakes);
260
+ for (const i of s.instances) {
261
+ console.log(`${w.name}/${s.name}/${i.label} ${i.status}${i.running ? ', running' : ''}${i.asks.length ? `, ${i.asks.length} asks waiting` : ''}, runner ${i.runner}`);
262
+ wakes(i.wakes);
263
+ }
234
264
  }
235
265
  } else if (cmd === 'pull' && args.length === 2) await pull(args[0], args[1]);
236
266
  else if (cmd === 'comment' && args.length === 2) {
@@ -253,11 +283,14 @@ else if (cmd === 'comment' && args.length === 2) {
253
283
  const q = new URLSearchParams({ name: basename(args[1]), pane: flags.output ? 'out' : 'in', ...(typeof flags.onto === 'string' && { onto: flags.onto }) });
254
284
  await api(`${(await find(args[0])).at}/upload?${q}`, { method: 'POST', body: readFileSync(args[1]) });
255
285
  console.log('uploaded');
256
- } else if (cmd === 'wake' && args.length >= 3) {
286
+ } else if (cmd === 'wake' && typeof flags.cancel === 'string' && !args.length) {
287
+ await api(`/api/wakes/${flags.cancel}`, { method: 'DELETE' });
288
+ console.log('cancelled');
289
+ } else if (cmd === 'wake' && args.length === 2) {
257
290
  const { series, inst } = await find(args[0]);
258
291
  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]);
259
- const w = await (await post(`/api/wakes/${inst?.id ?? series.id}`, { at: new Date(at).toISOString(), reason: args.slice(2).join(' '), label: flags.label }, 'PUT')).json();
260
- console.log(`wakes at ${w.at}`);
292
+ const w = await (await post(`/api/wakes/${inst?.id ?? series.id}`, { at: new Date(at).toISOString(), label: flags.label, days: flags.days }, 'PUT')).json();
293
+ console.log(`wake ${w.id} at ${w.at}${w.days ? `, then each ${w.days.join(', ')}` : ''}`);
261
294
  } else if (cmd === 'agents' && args.length <= 1) {
262
295
  const ws = args[0] === undefined ? undefined : (await get('/api')).find(w => w.name === args[0]);
263
296
  if (args[0] !== undefined && !ws) throw new Error(`no workspace ${args[0]}`);
@@ -271,23 +304,34 @@ else if (cmd === 'comment' && args.length === 2) {
271
304
  const files = Object.fromEntries(readdirSync(args[1], { recursive: true, withFileTypes: true }).filter(d => d.isFile())
272
305
  .map(d => [relative(args[1], join(d.parentPath, d.name)).split(sep).join('/'), readFileSync(join(d.parentPath, d.name)).toString('base64')]));
273
306
  console.log(await (await post(`/skills/${encodeURIComponent(basename(resolve(args[1])))}/versions`, { files })).text());
307
+ } else if (cmd === 'skill' && args[0] === 'pull' && args[1] && args.length <= 3) {
308
+ const id = encodeURIComponent(args[1]), dir = resolve(args[2] ?? args[1]), n = flags.version ?? (await get(`/skills/${id}/versions`)).at(-1)?.version;
309
+ if (n === undefined) throw new Error(`no skill ${args[1]}`);
310
+ 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`);
311
+ for (const [rel, data] of Object.entries (await get(`/skills/${id}/versions/${n}`))) {
312
+ const path = under(dir, rel);
313
+ if (!path) throw new Error(`${rel} can't be a file's name here`);
314
+ mkdirSync(dirname(path), { recursive: true });
315
+ writeFileSync(path, Buffer.from(data, 'base64'));
316
+ }
317
+ console.log(`pulled ${args[1]} version ${n} into ${dir}`);
274
318
  } else if (cmd === 'skill' && args[0] === 'versions' && args[1]) {
275
319
  for (const v of await get(`/skills/${encodeURIComponent(args[1])}/versions`)) console.log(`${v.version} ${v.at} ${v.by}`);
276
320
  } else if (cmd === 'skill' && args[0] === 'rollback' && args.length === 3) {
277
321
  console.log(await (await post(`/skills/${encodeURIComponent(args[1])}/versions`, { from: Number(args[2]) })).text());
278
322
  } else if (cmd === 'skills') {
279
323
  for (const s of await get('/skills')) console.log(`${s.id} v${s.pushed.version} by ${s.pushed.by} ${s.pushed.at} ${s.description}`);
280
- } else if (cmd === 'websites') {
281
- for (const w of await get('/websites')) console.log(`${w.id} ${w.url} ${w.hosts.join(' ') || '-'} ${w.name}`);
282
- } else if (cmd === 'website' && args[0] === 'set' && args.length === 3) {
283
- await post(`/websites/${encodeURIComponent(args[1])}`, { url: args[2], name: flags.name, hosts: typeof flags.hosts === 'string' ? flags.hosts.split(',') : [] }, 'PUT');
324
+ } else if (cmd === 'connections') {
325
+ for (const { name, type, login, updated_by, updated_at, ...settings } of await get('/connections')) console.log(`${name} ${type} ${JSON.stringify(settings)}`);
326
+ } else if (cmd === 'connection' && args[0] === 'set' && args.length === 3) {
327
+ await post(`/connections/${encodeURIComponent(args[1])}`, { type: args[2], ...flags }, 'PUT');
284
328
  console.log('saved');
285
- } else if (cmd === 'website' && args[0] === 'remove' && args[1]) {
286
- await api(`/websites/${encodeURIComponent(args[1])}`, { method: 'DELETE' });
329
+ } else if (cmd === 'connection' && args[0] === 'remove' && args[1]) {
330
+ await api(`/connections/${encodeURIComponent(args[1])}`, { method: 'DELETE' });
287
331
  console.log('removed');
288
332
  } else if (cmd === 'status' && !args.length) {
289
- const s = await get('/api/status'), long = Number(flags.long ?? 30);
290
- if (flags.json) console.log(JSON.stringify(s, null, 1));
333
+ const [s, ix] = await Promise.all([get('/api/status'), get('/api/indexes')]), long = Number(flags.long ?? 30);
334
+ if (flags.json) console.log(JSON.stringify({ ...s, indexes: ix }, null, 1));
291
335
  else {
292
336
  const sections = [
293
337
  [`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` : ''}`)],
@@ -295,12 +339,19 @@ else if (cmd === 'comment' && args.length === 2) {
295
339
  [`Waiting`, [
296
340
  ...s.asks.sort((a, b) => a.who.localeCompare(b.who) || a.since.localeCompare(b.since)).map(a => `${a.who} ${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)}`),
297
341
  ...s.expired.map(e => `${e.who} their ${e.login} login expired${e.holding.length ? `, holding ${e.holding.join(', ')}` : ''}`),
298
- ...s.requests.map(r => `${r.path} ${r.from} asks to start ${r.label}, since ${when(r.at)}: ${r.reason}`),
342
+ ...s.requests.map(r => `${r.path} ${r.from} asks to start ${r.label}, since ${when(r.at)}`),
299
343
  ]],
300
344
  [`Last run failed`, s.failed.map(f => `${f.path} run ${f.run} at ${when(f.at)}: ${f.error}`)],
345
+ [`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)
346
+ .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('; ')}`)],
301
347
  ].filter(([, rows]) => rows.length);
302
348
  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.');
303
349
  }
350
+ } else if (cmd === 'indexes' && !args.length) {
351
+ const ix = await get('/api/indexes');
352
+ if (flags.json) console.log(JSON.stringify(ix, null, 1));
353
+ else console.log(ix.map(x => [`${x.name} ${x.kind} ${x.items} items ${(x.bytes / 2 ** 20).toFixed(1)} MB`, ...x.people.map(p =>
354
+ ` ${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.');
304
355
  } else if (cmd === 'runs' && args.length <= 1) {
305
356
  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));
306
357
  if (flags.json) console.log(JSON.stringify(rows, null, 1));
@@ -326,10 +377,10 @@ else if (cmd === 'comment' && args.length === 2) {
326
377
  : (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(', ')}`] }));
327
378
  if (typeof flags.set !== 'string') {
328
379
  const w = Math.max(0, ...now.map(p => p.who.length));
329
- for (const p of now) console.log(`${p.kind.padEnd(9)} ${p.who.padEnd(w)} # ${p.note.filter(Boolean).join('; ')}`);
380
+ for (const p of now) console.log(`${p.kind.padEnd(6)} ${p.who.padEnd(w)} # ${p.note.filter(Boolean).join('; ')}`);
330
381
  if (!now.length) console.log('# no one is in it: only admins see it');
331
382
  } else {
332
- const kinds = ws ? ['owner', 'member'] : ['admin', 'publisher', 'user'];
383
+ const kinds = ws ? ['owner', 'member'] : ['admin', 'user'];
333
384
  const want = readFileSync(flags.set === '-' ? 0 : flags.set, 'utf8').split('\n').map(l => l.replace(/#.*/, '').trim()).filter(Boolean).map(l => l.split(/\s+/));
334
385
  const bad = want.find(([kind, who, more]) => !kinds.includes(kind) || !who || more);
335
386
  if (bad) throw new Error(`each line is ${kinds.join('|')} ${ws ? 'EMAIL-OR-GROUP' : 'EMAIL'}, not: ${bad.join(' ')}`);
@@ -353,6 +404,10 @@ else if (cmd === 'comment' && args.length === 2) {
353
404
  const { text, logo } = (await get('/me')).brand;
354
405
  console.log(text || logo ? `${text ?? 'no text'}, ${logo ? 'with a logo' : 'no logo'}` : 'no brand: the plain look');
355
406
  }
407
+ } else if (cmd === 'can' && args.length <= 2) {
408
+ const [cap, list] = args, people = flags.clear ? [] : list?.split(',').map(p => p.trim()).filter(Boolean);
409
+ const all = await (await (people ? post('/capabilities', { cap, people }, 'PUT') : api('/capabilities'))).json();
410
+ for (const [c, who] of Object.entries(all)) if (!cap || c === cap) console.log(`${c}: ${who.join(', ') || 'admins only'}`);
356
411
  } else if (cmd === 'user' && args.length >= 2) {
357
412
  const [what, email, role] = args, at = `/users/${encodeURIComponent(email)}`;
358
413
  if (what === 'add') await post('/users', { roles: { [email]: role ?? 'user' } }, 'PUT');