@rhizogrip/spore-cli 1.22.0 → 1.24.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/bin/spore.js CHANGED
@@ -69,6 +69,8 @@ const VERBS = `Usage:
69
69
  spore schedule rm <name> <sched> remove one; what it fired stays in the inbox
70
70
  spore schedule ls [<name>] its schedules, and why any is not firing
71
71
  spore tick fire every schedule that is due — run by a timer
72
+ spore approval ask <name> [<request.json>|-] ask people to choose, with buttons only they can press, where the request says
73
+ spore approval ls <name> the approvals asked in it, and how each ended
72
74
  spore job ls [<name>] its jobs: running ones with their progress, ended ones how
73
75
  spore job stop <name> <job> ask a running job's supervisor to stop it
74
76
  spore pause [why] stop every turn and job of your spores, and start none
@@ -149,6 +151,7 @@ const SHAPES = {
149
151
  upgrade: withJson(1, 'all'),
150
152
  plugin: { bare: 'ls', subs: { ls: withJson(0), show: withJson(1), allow: withJson(ALL), disallow: withJson(1) } },
151
153
  schedule: { bare: 'ls', subs: { set: withJson(3), rm: withJson(2), ls: withJson(1) } },
154
+ approval: { bare: 'ls', subs: { ask: withJson(2), ls: withJson(1) } },
152
155
  job: { bare: 'ls', subs: { ls: withJson(1), stop: withJson(2) } },
153
156
  tick: withJson(0),
154
157
  pause: withJson(ALL),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-cli",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "author": {
5
5
  "name": "Christophe Le Bars",
6
6
  "email": "clb@toort.net"
@@ -50,7 +50,7 @@
50
50
  "tui": "node bin/spore.js tui"
51
51
  },
52
52
  "dependencies": {
53
- "@rhizogrip/spore": "1.22.0",
53
+ "@rhizogrip/spore": "1.24.0",
54
54
  "chalk": "^6.0.1",
55
55
  "minimist": "^1.2.8"
56
56
  },
package/src/dispatch.js CHANGED
@@ -15,8 +15,8 @@ import { basename, join, resolve } from 'node:path'
15
15
 
16
16
  import {
17
17
  addTo, allowPlugin, billingFor, changeText, define, defaultModel, disallowPlugin, durationText,
18
- edit, extend, getKey, jobs, list, listPlugins, log, pause, precursors, remake, remove,
19
- removeFrom, removeSchedule, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings,
18
+ edit, extend, getKey, jobs, list, listApprovals, listPlugins, log, pause, precursors, remake, remove,
19
+ removeFrom, removeSchedule, requestApproval, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings,
20
20
  show, showPlugin, sql, stateWord, stopJob, switchModel, tick, tickReport, unmetered, unpause, upgrade, usage, wrap, CONFIG_FILE, DEFAULT_SPORANGIUM
21
21
  } from '@rhizogrip/spore'
22
22
  import { diagnose, renderDoctor } from './doctor.js'
@@ -290,6 +290,20 @@ function renderSchedules (result) {
290
290
  if (!result.schedules.length) console.log('none — nothing here is said by the clock')
291
291
  }
292
292
 
293
+ function renderApprovals (result) {
294
+ const ended = (one) => {
295
+ if (one.state === 'answered') {
296
+ const host = one.outcome === 'failed' ? `, not confirmed — ${one.reason}` : one.outcome ? `, ${one.outcome}` : ''
297
+ return `${one.choice} by ${one.answererName}${host}`
298
+ }
299
+ if (one.state === 'refused') return `refused — ${one.reason}`
300
+ if (one.state === 'expired') return 'expired'
301
+ return `${one.state}, until ${when(one.until)}`
302
+ }
303
+ for (const one of result.approvals) console.log(`${one.id} ${when(one.at)} ${one.place} ${ended(one)}`)
304
+ if (!result.approvals.length) console.log('none — nothing was asked here')
305
+ }
306
+
293
307
  async function readStdin () {
294
308
  if (process.stdin.isTTY) return ''
295
309
  const chunks = []
@@ -714,6 +728,27 @@ export async function manage (verb, argv) {
714
728
  const source = !from || from === '-' ? await readStdin() : readFileSync(resolve(from), 'utf8')
715
729
  return emit(setSchedule({ ws, name, source }), (r) => { console.log(`scheduled ${r.name} — ${r.path}`) })
716
730
  }
731
+ if (verb === 'approval') {
732
+ const [, sub = 'ls', ws, from] = argv._
733
+ if (sub !== 'ask' && sub !== 'ls') {
734
+ console.error(`spore: approval has no "${sub}" — ask, ls`)
735
+ return 2
736
+ }
737
+ if (!ws) {
738
+ console.error(`spore: approval ${sub} needs a spore — ${sub === 'ask' ? 'spore approval ask <name> [<request.json>|-]' : 'spore approval ls <name>'}`)
739
+ return 2
740
+ }
741
+ if (sub === 'ls') return emit(listApprovals({ ws }), renderApprovals)
742
+ const source = !from || from === '-' ? await readStdin() : readFileSync(resolve(from), 'utf8')
743
+ let request
744
+ try {
745
+ request = JSON.parse(source)
746
+ } catch (err) {
747
+ console.error(`spore: the request is not JSON — ${err.message}`)
748
+ return 2
749
+ }
750
+ return emit(requestApproval({ ws, request }), (r) => { console.log(`asked ${r.approval}, open until ${when(r.until)} — the service of the place it names posts it`) })
751
+ }
717
752
  if (verb === 'rm') {
718
753
  const name = argv._[1]
719
754
  if (!name) {