@rhizogrip/spore-cli 1.25.1 → 1.27.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 +7 -4
- package/package.json +2 -2
- package/src/dispatch.js +18 -1
- package/tui/conversation.js +0 -68
- package/tui/index.js +12 -12
package/bin/spore.js
CHANGED
|
@@ -25,7 +25,7 @@ const DEFAULT_TAIL = 50
|
|
|
25
25
|
|
|
26
26
|
const argv = minimist(process.argv.slice(2), {
|
|
27
27
|
string: ['_', 'definition', 'from', 'sporangium', 'at', 'model', 'plugin', 'attach', 'request-id', 'after', 'since', 'until', 'tz', 'by', 'n', 'lines'],
|
|
28
|
-
boolean: ['debug', 'help', 'version', 'unsafe', 'yes', 'replay', 'json', 'all', 'outdated', 'f'],
|
|
28
|
+
boolean: ['debug', 'help', 'version', 'unsafe', 'yes', 'replay', 'json', 'all', 'outdated', 'f', 'clear'],
|
|
29
29
|
alias: { h: 'help' }
|
|
30
30
|
})
|
|
31
31
|
|
|
@@ -48,6 +48,7 @@ const VERBS = `Usage:
|
|
|
48
48
|
spore stop <name> SIGTERM it, mid-round
|
|
49
49
|
spore extend <name> wall 30m|cost 1.50|rounds 20 give the running turn more, up to its extend.<limit>
|
|
50
50
|
spore wrap <name> [10m] ask the running turn to wrap up, now or in a while
|
|
51
|
+
spore annotate <name> <line>|--clear a line of yours under the running turn's header, wherever it is shown
|
|
51
52
|
spore model [<name> [<model>]] what it runs on and may switch to; with a model, switch from the next turn
|
|
52
53
|
spore ls [<dir>] your spores and their state
|
|
53
54
|
spore tui [<name>] talk to a spore in a terminal screen; the last one opened without a name
|
|
@@ -138,6 +139,7 @@ const SHAPES = {
|
|
|
138
139
|
stop: { flags: [], most: 1 },
|
|
139
140
|
extend: withJson(3),
|
|
140
141
|
wrap: withJson(2),
|
|
142
|
+
annotate: withJson(ALL, 'clear'),
|
|
141
143
|
model: withJson(2),
|
|
142
144
|
define: withJson(1, 'definition', 'from', 'sporangium', 'model', 'plugin'),
|
|
143
145
|
edit: withJson(1),
|
|
@@ -374,7 +376,7 @@ if (verb === 'fork') {
|
|
|
374
376
|
}
|
|
375
377
|
console.error(`spore: forked ${made.from} at ${made.at}, round ${made.rounds} — carrying it on in ${made.ws}`)
|
|
376
378
|
renderHeader(made.ws, grantOf(made.ws))
|
|
377
|
-
const ended = await follow(made.ws, { lines: 0 })
|
|
379
|
+
const ended = await follow(made.ws, { lines: 0, status: true })
|
|
378
380
|
if (ended === 'detached') {
|
|
379
381
|
process.stderr.write(`\nspore: still running — spore attach ${made.ws}\n`)
|
|
380
382
|
process.exit(DETACHED)
|
|
@@ -394,7 +396,8 @@ if (verb === 'attach') {
|
|
|
394
396
|
if (argv.after !== undefined) fail('--after is for --json — spore attach <name> --json --after <seq>')
|
|
395
397
|
const tail = argv.n ?? argv.lines
|
|
396
398
|
if (tail !== undefined && !/^\d+$/.test(tail)) fail(`-n ${tail} is not a number of lines`)
|
|
397
|
-
const
|
|
399
|
+
const running = stateOf(ws).state === RUNNING
|
|
400
|
+
const ended = await follow(ws, { lines: tail !== undefined ? Number(tail) : running ? 0 : DEFAULT_TAIL, status: true })
|
|
398
401
|
process.exit(ended === 'detached' ? DETACHED : exitFor(ws))
|
|
399
402
|
}
|
|
400
403
|
|
|
@@ -464,7 +467,7 @@ if (settled) {
|
|
|
464
467
|
|
|
465
468
|
if (sent.started) renderHeader(ws, grant)
|
|
466
469
|
|
|
467
|
-
const ended = await follow(ws, { lines: 0 })
|
|
470
|
+
const ended = await follow(ws, { lines: 0, status: true })
|
|
468
471
|
if (ended === 'detached') {
|
|
469
472
|
process.stderr.write(`\nspore: still running — spore attach ${asked}\n`)
|
|
470
473
|
process.exit(DETACHED)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhizogrip/spore-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.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.
|
|
53
|
+
"@rhizogrip/spore": "1.27.0",
|
|
54
54
|
"chalk": "^6.0.1",
|
|
55
55
|
"minimist": "^1.2.8"
|
|
56
56
|
},
|
package/src/dispatch.js
CHANGED
|
@@ -14,7 +14,7 @@ import { homedir } from 'node:os'
|
|
|
14
14
|
import { basename, join, resolve } from 'node:path'
|
|
15
15
|
|
|
16
16
|
import {
|
|
17
|
-
addTo, allowPlugin, billingFor, changeText, define, defaultModel, disallowPlugin, durationText,
|
|
17
|
+
addTo, allowPlugin, annotate, billingFor, changeText, define, defaultModel, disallowPlugin, durationText,
|
|
18
18
|
edit, extend, getKey, jobs, list, listApprovals, listPlugins, log, pause, precursors, remake, remove,
|
|
19
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
|
|
@@ -238,6 +238,14 @@ function renderChange (answer) {
|
|
|
238
238
|
|
|
239
239
|
const changeExit = (answer) => (answer.refused ? 1 : 0)
|
|
240
240
|
|
|
241
|
+
const renderAnnotation = (text) => (answer) => {
|
|
242
|
+
if (answer.refused) {
|
|
243
|
+
console.error('spore: nothing is running — a line is shown under a running turn and goes when it ends')
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
console.log(text === null ? 'its line was taken away' : 'shown under the running turn')
|
|
247
|
+
}
|
|
248
|
+
|
|
241
249
|
const pausedText = (mark) => `paused${mark.at ? ` since ${mark.at}` : ''}${mark.why ? ` (${mark.why})` : ''}`
|
|
242
250
|
|
|
243
251
|
function renderPause (result) {
|
|
@@ -694,6 +702,15 @@ export async function manage (verb, argv) {
|
|
|
694
702
|
}
|
|
695
703
|
return emit(wrap({ ws, wait }), renderChange, changeExit)
|
|
696
704
|
}
|
|
705
|
+
if (verb === 'annotate') {
|
|
706
|
+
const [, ws, ...words] = argv._.map(String)
|
|
707
|
+
const text = argv.clear ? null : words.join(' ')
|
|
708
|
+
if (!ws || (argv.clear ? words.length : !text.trim())) {
|
|
709
|
+
console.error('spore: annotate needs a spore and a line, or --clear — spore annotate <name> <line>|--clear')
|
|
710
|
+
return 2
|
|
711
|
+
}
|
|
712
|
+
return emit(annotate({ ws, text }), renderAnnotation(text), changeExit)
|
|
713
|
+
}
|
|
697
714
|
if (verb === 'job') {
|
|
698
715
|
const [, sub, ws, name] = argv._
|
|
699
716
|
if (!sub || sub === 'ls') return emit(jobs({ ws }), renderJobs)
|
package/tui/conversation.js
CHANGED
|
@@ -50,74 +50,6 @@ export function history ({ turns, inbox }) {
|
|
|
50
50
|
return items
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export const createLive = () => ({ text: '', notes: [], tools: [], rounds: 0, input: null, cached: 0, cost: 0, complete: null })
|
|
54
|
-
|
|
55
|
-
/** The running turn from its events so far, or null when there are none: a turn's end is recorded before its lock is let go. */
|
|
56
|
-
export function liveOf (events) {
|
|
57
|
-
if (!events.length) return null
|
|
58
|
-
const live = createLive()
|
|
59
|
-
for (const event of events) applyEvent(live, event)
|
|
60
|
-
return live
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** False when the event changes nothing shown. Text written before a tool call is a note: the answer is what comes last. */
|
|
64
|
-
export function applyEvent (live, event) {
|
|
65
|
-
switch (event.event) {
|
|
66
|
-
case 'round':
|
|
67
|
-
live.rounds = event.index + 1
|
|
68
|
-
return true
|
|
69
|
-
case 'stream':
|
|
70
|
-
if (event.kind !== 'message') return false
|
|
71
|
-
live.text += event.delta
|
|
72
|
-
return true
|
|
73
|
-
case 'tool_start':
|
|
74
|
-
if (live.text.trim()) live.notes.push({ kind: 'thought', text: printable(live.text.trim()) })
|
|
75
|
-
live.text = ''
|
|
76
|
-
live.tools.push({ callId: event.callId, name: event.name, args: event.args ?? {}, done: false })
|
|
77
|
-
return true
|
|
78
|
-
case 'tool_end': {
|
|
79
|
-
const tool = live.tools.find(t => t.callId === event.callId)
|
|
80
|
-
if (!tool) return false
|
|
81
|
-
Object.assign(tool, {
|
|
82
|
-
done: true,
|
|
83
|
-
durationMs: event.durationMs,
|
|
84
|
-
error: Boolean(event.error),
|
|
85
|
-
outcome: event.outcome,
|
|
86
|
-
exit: event.exit,
|
|
87
|
-
killed: event.killed,
|
|
88
|
-
signal: event.signal
|
|
89
|
-
})
|
|
90
|
-
return true
|
|
91
|
-
}
|
|
92
|
-
case 'usage':
|
|
93
|
-
live.input = event.input + event.cacheRead + event.cacheWrite
|
|
94
|
-
live.cached = event.cacheRead
|
|
95
|
-
live.cost += event.cost
|
|
96
|
-
return true
|
|
97
|
-
case 'interject':
|
|
98
|
-
live.notes.push({ kind: 'note', text: 'a message arrived mid-turn' })
|
|
99
|
-
return true
|
|
100
|
-
case 'wrap':
|
|
101
|
-
live.notes.push({ kind: 'note', text: `wrapping up — reached its ${event.dimension} limit` })
|
|
102
|
-
return true
|
|
103
|
-
case 'compaction_started':
|
|
104
|
-
live.notes.push({ kind: 'note', text: `summarizing ${event.messages} earlier messages before the first round…` })
|
|
105
|
-
return true
|
|
106
|
-
case 'compaction':
|
|
107
|
-
live.notes.push({ kind: 'note', text: 'earlier turns summarized' })
|
|
108
|
-
return true
|
|
109
|
-
case 'compaction_failed':
|
|
110
|
-
live.notes.push({ kind: 'note', text: `earlier turns are over their bound and were not summarized — ${event.why}` })
|
|
111
|
-
return true
|
|
112
|
-
case 'complete':
|
|
113
|
-
live.complete = { stopReason: event.stopReason ?? 'answer', output: event.output == null ? null : printable(event.output) }
|
|
114
|
-
if (live.complete.output) live.text = live.complete.output
|
|
115
|
-
return true
|
|
116
|
-
default:
|
|
117
|
-
return false
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
53
|
/**
|
|
122
54
|
* What a call's line starts with: whether it worked, the exit code of a command that ran to its
|
|
123
55
|
* end and said no, or how it failed. A tool_end a runtime before outcomes recorded has only `error`.
|
package/tui/index.js
CHANGED
|
@@ -4,12 +4,12 @@ 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 { changeText, curate, durationText, extendTurn, grantOf, list, loadMohdelEnvironment, outbox, pause, paused,
|
|
7
|
+
import { applyEvent, changeText, createLive, curate, durationText, extendTurn, grantOf, list, liveIn, loadMohdelEnvironment, outbox, pause, paused, readInbox, readTurns, RUNNING, send, SERVICE_STATE_DIR, show, 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'
|
|
11
11
|
import { COMMANDS, parseCommand } from './commands.js'
|
|
12
|
-
import {
|
|
12
|
+
import { history, markOf } from './conversation.js'
|
|
13
13
|
import { changeOf, counts, hunks } from './diff.js'
|
|
14
14
|
import { printable } from './printable.js'
|
|
15
15
|
import { PromptEditor } from './prompt.js'
|
|
@@ -138,13 +138,14 @@ class Conversation {
|
|
|
138
138
|
}
|
|
139
139
|
if (this.live) {
|
|
140
140
|
out.push('')
|
|
141
|
-
|
|
142
|
-
for (const
|
|
141
|
+
if (this.live.annotation) out.push(...lines(printable(this.live.annotation), width, dim))
|
|
142
|
+
for (const note of this.live.notes) out.push(...lines(printable(note.text), width, note.kind === 'thought' ? chalk.italic : dim))
|
|
143
|
+
for (const call of this.live.calls) out.push(...(this.renderTool?.(call, { expanded: this.expanded, width }) ?? toolLine(call, { expanded: this.expanded, width })))
|
|
143
144
|
if (this.live.text.trim()) {
|
|
144
|
-
this.liveAnswer.setText(this.live.text)
|
|
145
|
-
if (this.live.notes.length || this.live.
|
|
145
|
+
this.liveAnswer.setText(printable(this.live.text))
|
|
146
|
+
if (this.live.notes.length || this.live.calls.length) out.push('')
|
|
146
147
|
out.push(...this.liveAnswer.render(width))
|
|
147
|
-
} else if (!this.live.complete && this.live.
|
|
148
|
+
} else if (!this.live.complete && this.live.calls.every(call => call.done)) {
|
|
148
149
|
out.push(dim(`thinking${'.'.repeat(1 + Math.floor(Date.now() / 1000) % 3)}`))
|
|
149
150
|
}
|
|
150
151
|
}
|
|
@@ -320,11 +321,10 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
320
321
|
conversation.items = history({ turns: readTurns(state.ws), inbox: readInbox(state.ws) })
|
|
321
322
|
conversation.live = null
|
|
322
323
|
state.limits = null
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
conversation.live = liveOf(events)
|
|
324
|
+
const running = liveIn(state.ws)
|
|
325
|
+
if (running) {
|
|
326
|
+
state.lastSeq = running.seq
|
|
327
|
+
conversation.live = running.live
|
|
328
328
|
}
|
|
329
329
|
conversation.invalidate()
|
|
330
330
|
refresh()
|