@rhizogrip/spore-cli 1.37.1 → 1.38.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
@@ -51,6 +51,7 @@ const VERBS = `Usage:
51
51
  spore wrap <name> [10m] ask the running turn to wrap up, now or in a while
52
52
  spore annotate <name> <line>|--clear a line of yours under the running turn's header, wherever it is shown
53
53
  spore model [<name> [<model>]] what it runs on and may switch to; with a model, switch from the next turn
54
+ spore flush <name> its next turn starts over, replaying nothing said before; nothing is forgotten
54
55
  spore ls [<dir>] your spores and their state
55
56
  spore tui [<name>] talk to a spore in a terminal screen; the last one opened without a name
56
57
  spore here [<dir>] the spore that works in this directory, in place — made the first time
@@ -140,6 +141,7 @@ const SHAPES = {
140
141
  wrap: withJson(2),
141
142
  annotate: withJson(ALL, 'clear'),
142
143
  model: withJson(2),
144
+ flush: withJson(1),
143
145
  define: withJson(1, 'definition', 'from', 'sporangium', 'model', 'plugin'),
144
146
  edit: withJson(1),
145
147
  remake: withJson(1),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-cli",
3
- "version": "1.37.1",
3
+ "version": "1.38.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.37.1",
53
+ "@rhizogrip/spore": "1.38.0",
54
54
  "chalk": "^6.0.1",
55
55
  "minimist": "^1.2.8"
56
56
  },
package/src/dispatch.js CHANGED
@@ -13,7 +13,7 @@ import { readFileSync } from 'node:fs'
13
13
  import { homedir } from 'node:os'
14
14
  import { basename, join, resolve } from 'node:path'
15
15
 
16
- import { addTo, allowPlugin, annotate, billingFor, bytesText, changeText, define, defaultModel, disallowPlugin, durationText, edit, extend, getKey, jobs, list, listApprovals, listPlugins, log, pause, remake, remove, removeFrom, removeSchedule, requestApproval, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings, show, showPlugin, sql, stateWord, stopJob, switchModel, tick, tickReport, unmetered, unpause, upgrade, usage, wrap, CONFIG_FILE, DEFAULT_SPORANGIUM, errorText } from '@rhizogrip/spore'
16
+ import { addTo, allowPlugin, annotate, billingFor, bytesText, changeText, define, defaultModel, disallowPlugin, durationText, edit, extend, flush, getKey, jobs, list, listApprovals, listPlugins, log, pause, remake, remove, removeFrom, removeSchedule, requestApproval, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings, show, showPlugin, sql, stateWord, stopJob, switchModel, tick, tickReport, unmetered, unpause, upgrade, usage, wrap, CONFIG_FILE, DEFAULT_SPORANGIUM, errorText } from '@rhizogrip/spore'
17
17
  import { diagnose, renderDoctor } from './doctor.js'
18
18
  import { hook } from './hooks.js'
19
19
  import { createServices } from './services.js'
@@ -69,6 +69,16 @@ function renderModels ({ model, models }) {
69
69
  console.log(models.length ? `or: ${models.join(', ')} — spore model <name> <model> switches from the next turn` : 'offers no other — models: [<provider>/<name>, …] in its spore.cmk adds some')
70
70
  }
71
71
 
72
+ function renderFlush ({ open }) {
73
+ console.log('flushed — its next turn starts over, replaying nothing said before; nothing is forgotten')
74
+ const still = [
75
+ ...(open.question ? [`the question it asked: ${cut(open.question)}`] : []),
76
+ ...open.approvals.map(one => `approval ${one.id} in ${one.place}, open until ${when(one.until)}`),
77
+ ...open.jobs.map(one => `job ${one.name}, running since ${when(one.startedAt)}`)
78
+ ]
79
+ if (still.length) console.log(`still open, and it is told so:\n${still.map(line => ` ${line}`).join('\n')}`)
80
+ }
81
+
72
82
  function renderSwitch ({ model, was }) {
73
83
  console.log(model === was ? `already runs on ${model}` : `runs on ${model} from the next turn — it ran on ${was}`)
74
84
  }
@@ -298,7 +308,7 @@ const cut = (text) => (text.length > 60 ? text.slice(0, 57) + '…' : text)
298
308
  const quoted = (entries) => entries.map(entry => `${saidBy(entry) ? `${saidBy(entry)}: ` : ''}${JSON.stringify(cut(saidText(entry)))}`).join(' ')
299
309
 
300
310
  function renderLog (result) {
301
- if (!result.turns.length && !result.waiting.length && !result.setAside.length && !result.held.length) {
311
+ if (!result.turns.length && !result.flushes.length && !result.waiting.length && !result.setAside.length && !result.held.length) {
302
312
  console.log('nothing has been said here yet')
303
313
  return
304
314
  }
@@ -308,10 +318,17 @@ function renderLog (result) {
308
318
  const text = `${turn.error}${detail}`
309
319
  return `${text.length > 100 ? `${text.slice(0, 99)}…` : text} `
310
320
  }
311
- for (const turn of result.turns) {
312
- console.log(` ${when(turn.endedAt)} ${(turn.stopReason || '—').padEnd(12)} ${String(turn.rounds).padStart(3)}r ` +
313
- `${('$' + turn.treeUsd.toFixed(4)).padStart(9)} ${String(turn.workUnits).padStart(4)}u ${why(turn)}${quoted(turn.asked)}`)
314
- }
321
+ const timeline = [
322
+ ...result.turns.map(turn => ({
323
+ at: turn.endedAt,
324
+ line: ` ${when(turn.endedAt)} ${(turn.stopReason || '—').padEnd(12)} ${String(turn.rounds).padStart(3)}r ` +
325
+ `${('$' + turn.treeUsd.toFixed(4)).padStart(9)} ${String(turn.workUnits).padStart(4)}u ${why(turn)}${quoted(turn.asked)}`
326
+ })),
327
+ ...result.flushes.map(one => ({ at: one.at, line: ` ${when(one.at)} ${'flushed'.padEnd(12)} ${' '.repeat(19)} by ${one.by}` }))
328
+ ]
329
+ const order = (at) => at ?? '\uffff'
330
+ timeline.sort((a, b) => order(a.at) < order(b.at) ? -1 : order(a.at) > order(b.at) ? 1 : 0)
331
+ for (const { line } of timeline) console.log(line)
315
332
  // The time column is when a turn ended, and a waiting message has not been answered by
316
333
  // one. Blank says that; when it was said is in the record for anyone who needs it.
317
334
  for (const entry of result.setAside) {
@@ -653,6 +670,14 @@ export async function manage (verb, argv) {
653
670
  const shown = show({ ws })
654
671
  return emit({ ws: shown.ws, model: shown.model, models: shown.models }, renderModels)
655
672
  }
673
+ if (verb === 'flush') {
674
+ const ws = argv._[1]
675
+ if (!ws) {
676
+ console.error('spore: flush needs a spore — spore flush <name>')
677
+ return 2
678
+ }
679
+ return emit(flush({ ws: String(ws), by: 'its operator' }), renderFlush)
680
+ }
656
681
  if (verb === 'extend') {
657
682
  const [, ws, dimension, amount] = argv._.map(String)
658
683
  if (!ws || !dimension || !amount) {
package/tui/commands.js CHANGED
@@ -3,6 +3,7 @@ export const COMMANDS = [
3
3
  { name: 'wrap', description: 'ask the running turn to wrap up, now or in a while', argumentHint: '[10m]' },
4
4
  { name: 'extend', description: 'give the running turn more, as far as its spore.cmk allows', argumentHint: '<rounds|cost|wall> <amount>' },
5
5
  { name: 'model', description: 'switch the model this spore runs on, from the next turn — a list to pick from, or one named', argumentHint: '[<model>]' },
6
+ { name: 'flush', description: 'start the conversation over from the next turn; nothing is forgotten' },
6
7
  { name: 'curate', description: 'add a model a provider lists to your mohdel catalog — this spore\'s provider unless one is named', argumentHint: '[<provider>]' },
7
8
  { name: 'pause', description: 'stop every turn and job of your spores, and start none' },
8
9
  { name: 'unpause', description: 'let turns start again' },
package/tui/index.js CHANGED
@@ -4,7 +4,7 @@ import { tmpdir } from 'node:os'
4
4
  import { basename, dirname, join } from 'node:path'
5
5
 
6
6
  import { CombinedAutocompleteProvider, Input, isKeyRelease, Markdown, matchesKey, ProcessTerminal, ScrollView, SelectList, truncateToWidth, TuiAltScreen, visibleWidth, VStack, wrapTextWithAnsi } from '@earendil-works/pi-tui'
7
- import { applyEvent, changeText, createLive, curate, durationText, errorText, extendTurn, grantOf, list, liveIn, loadMohdelEnvironment, outbox, pause, paused, readInbox, readTurns, RUNNING, send, SERVICE_STATE_DIR, show, sporePaths, stateOf, stop, switchModel, unpause, upstream, watchAll, wrapTurn } from '@rhizogrip/spore'
7
+ import { applyEvent, changeText, createLive, curate, durationText, errorText, extendTurn, flush, grantOf, list, liveIn, loadMohdelEnvironment, outbox, pause, paused, readInbox, readTurns, RUNNING, send, SERVICE_STATE_DIR, show, sporePaths, stateOf, stop, switchModel, unpause, upstream, watchAll, wrapTurn } from '@rhizogrip/spore'
8
8
  import chalk from 'chalk'
9
9
 
10
10
  import { runningJob, scheduleLine } from '../src/dispatch.js'
@@ -465,6 +465,15 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
465
465
  onCancel: closeOverlay
466
466
  }))
467
467
  }
468
+ if (name === 'flush') {
469
+ try {
470
+ const { open } = flush({ ws: state.ws, by: 'its operator' })
471
+ const still = (open.question ? 1 : 0) + open.approvals.length + open.jobs.length
472
+ return notice(`flushed — the next turn starts over; nothing is forgotten${still ? `, and it is told of ${still} thing${still > 1 ? 's' : ''} still open` : ''}`)
473
+ } catch (err) {
474
+ return notice(errorText(err))
475
+ }
476
+ }
468
477
  if (name === 'curate') {
469
478
  const provider = args[0] ?? show({ ws: state.ws }).model.split('/')[0]
470
479
  loadMohdelEnvironment()