@rhizogrip/spore-cli 1.35.0 → 1.36.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 +8 -8
- package/package.json +2 -2
- package/src/dispatch.js +7 -23
- package/src/hooks.js +3 -9
- package/src/services.js +22 -47
- package/tui/conversation.js +6 -7
- package/tui/index.js +4 -4
package/bin/spore.js
CHANGED
|
@@ -14,7 +14,7 @@ import { basename, resolve } from 'node:path'
|
|
|
14
14
|
|
|
15
15
|
import minimist from 'minimist'
|
|
16
16
|
|
|
17
|
-
import { differingDocs, fork, follow, followingDocs, grantOf, isWorkspace, lastEventSeq, loadEnvironment, mimeOf, readConfig, readInbox, RUNNING, send, stateOf, stop, turnOfMessage, turnSummary, watch, workspaceFor } from '@rhizogrip/spore'
|
|
17
|
+
import { differingDocs, fork, follow, followingDocs, grantOf, isWorkspace, lastEventSeq, loadEnvironment, mimeOf, readConfig, readInbox, RUNNING, send, stateOf, stop, turnOfMessage, turnSummary, watch, workspaceFor, errorText } from '@rhizogrip/spore'
|
|
18
18
|
import { renderHeader } from '../src/dispatch.js'
|
|
19
19
|
|
|
20
20
|
// Detaching is neither success nor failure: the turn is still going, and 0 would claim it
|
|
@@ -240,7 +240,7 @@ if (shape) {
|
|
|
240
240
|
try {
|
|
241
241
|
loadEnvironment()
|
|
242
242
|
} catch (err) {
|
|
243
|
-
if (verb !== 'doctor') fail(
|
|
243
|
+
if (verb !== 'doctor') fail(errorText(err))
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
if (verb === 'tui') {
|
|
@@ -261,7 +261,7 @@ if (verb === 'setup') {
|
|
|
261
261
|
process.exit(await setup())
|
|
262
262
|
} catch (err) {
|
|
263
263
|
if (!err.type) throw err
|
|
264
|
-
fail(err
|
|
264
|
+
fail(errorText(err))
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -271,7 +271,7 @@ if (verb === 'here') {
|
|
|
271
271
|
process.exit(await here({ dir: argv._[1], sporangium: argv.sporangium, model: argv.model, git: argv.git !== false }))
|
|
272
272
|
} catch (err) {
|
|
273
273
|
if (!err.type) throw err
|
|
274
|
-
fail(err
|
|
274
|
+
fail(errorText(err))
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
@@ -338,7 +338,7 @@ function spore (name, { needed = true } = {}) {
|
|
|
338
338
|
try {
|
|
339
339
|
target = workspaceFor(name)
|
|
340
340
|
} catch (err) {
|
|
341
|
-
fail(
|
|
341
|
+
fail(errorText(err))
|
|
342
342
|
}
|
|
343
343
|
if (needed && !isWorkspace(target.path)) {
|
|
344
344
|
fail(target.named
|
|
@@ -372,7 +372,7 @@ if (verb === 'fork') {
|
|
|
372
372
|
try {
|
|
373
373
|
made = fork({ run: spore(asked), at: argv.at, into: workspaceFor(into).path, definition: argv.definition, replay: argv.replay, unsafe: argv.unsafe, debug: argv.debug })
|
|
374
374
|
} catch (err) {
|
|
375
|
-
fail(err
|
|
375
|
+
fail(errorText(err))
|
|
376
376
|
}
|
|
377
377
|
console.error(`spore: forked ${made.from} at ${made.at}, round ${made.rounds} — carrying it on in ${made.ws}`)
|
|
378
378
|
renderHeader(made.ws, grantOf(made.ws))
|
|
@@ -423,7 +423,7 @@ try {
|
|
|
423
423
|
differs = differingDocs(ws)
|
|
424
424
|
followed = followingDocs(readConfig())
|
|
425
425
|
} catch (err) {
|
|
426
|
-
fail(err
|
|
426
|
+
fail(errorText(err))
|
|
427
427
|
}
|
|
428
428
|
if (differs.length && !followed) console.error(`spore: ${differs.map(d => d.file).join(', ')} differ from what is installed — spore upgrade ${asked}`)
|
|
429
429
|
|
|
@@ -436,7 +436,7 @@ try {
|
|
|
436
436
|
grant = grantOf(ws)
|
|
437
437
|
sent = send(ws, message, { attach, requestId, replyTo: 'terminal', unsafe: argv.unsafe, debug: argv.debug })
|
|
438
438
|
} catch (err) {
|
|
439
|
-
fail(err
|
|
439
|
+
fail(errorText(err))
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
// Sent before under this request id and already ended: nothing runs, and what it got is on
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhizogrip/spore-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.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.36.0",
|
|
54
54
|
"chalk": "^6.0.1",
|
|
55
55
|
"minimist": "^1.2.8"
|
|
56
56
|
},
|
package/src/dispatch.js
CHANGED
|
@@ -13,12 +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 {
|
|
17
|
-
addTo, allowPlugin, annotate, billingFor, changeText, define, defaultModel, disallowPlugin, durationText,
|
|
18
|
-
edit, extend, getKey, jobs, list, listApprovals, listPlugins, log, pause, precursors, remake, remove,
|
|
19
|
-
removeFrom, removeSchedule, requestApproval, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings,
|
|
20
|
-
show, showPlugin, sql, stateWord, stopJob, switchModel, tick, tickReport, unmetered, unpause, upgrade, usage, wrap, CONFIG_FILE, DEFAULT_SPORANGIUM
|
|
21
|
-
} from '@rhizogrip/spore'
|
|
16
|
+
import { addTo, allowPlugin, annotate, billingFor, bytesText, changeText, define, defaultModel, disallowPlugin, durationText, edit, extend, getKey, jobs, list, listApprovals, listPlugins, log, pause, precursors, 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'
|
|
22
17
|
import { diagnose, renderDoctor } from './doctor.js'
|
|
23
18
|
import { hook } from './hooks.js'
|
|
24
19
|
import { createServices } from './services.js'
|
|
@@ -26,17 +21,6 @@ import { saidBy, saidText } from '../tui/conversation.js'
|
|
|
26
21
|
|
|
27
22
|
const STATE_WIDTH = 9
|
|
28
23
|
|
|
29
|
-
const size = (bytes) => {
|
|
30
|
-
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
|
31
|
-
let value = bytes
|
|
32
|
-
let unit = 0
|
|
33
|
-
while (value >= 1024 && unit < units.length - 1) {
|
|
34
|
-
value /= 1024
|
|
35
|
-
unit++
|
|
36
|
-
}
|
|
37
|
-
return `${unit ? value.toFixed(1) : value}${units[unit]}`
|
|
38
|
-
}
|
|
39
|
-
|
|
40
24
|
const tilde = (path) => (path === homedir() || path.startsWith(homedir() + '/') ? `~${path.slice(homedir().length)}` : path)
|
|
41
25
|
|
|
42
26
|
const line = (row, under) => {
|
|
@@ -44,7 +28,7 @@ const line = (row, under) => {
|
|
|
44
28
|
const spend = row.treeUsd ? `$${row.treeUsd.toFixed(4)}` : ''
|
|
45
29
|
const works = row.definitionError ? ' (its spore.cmk does not parse)' : row.writes.map(path => ` → ${tilde(path)}`).join('')
|
|
46
30
|
const over = row.historyOver ? ' (history over its bound)' : ''
|
|
47
|
-
return ` ${stateWord(row).padEnd(STATE_WIDTH)} ${String(row.lastTurnNo).padStart(4)} turns ${spend.padStart(9)} ${
|
|
31
|
+
return ` ${stateWord(row).padEnd(STATE_WIDTH)} ${String(row.lastTurnNo).padStart(4)} turns ${spend.padStart(9)} ${bytesText(row.bytes).padStart(8)} ${where}${works}${over}`
|
|
48
32
|
}
|
|
49
33
|
|
|
50
34
|
const block = (title, rows, under) => {
|
|
@@ -156,6 +140,7 @@ function renderShow (result) {
|
|
|
156
140
|
}).join(', '))
|
|
157
141
|
}
|
|
158
142
|
if (result.reads?.length) line('reads', result.reads.map(r => `${r.name} → ${r.path}`).join(', '))
|
|
143
|
+
if (result.prepare) line('prepare', `${result.prepare.steps.map(step => `${step.origin} by ${step.plugin}/${step.program}`).join(', ')} — up to ${durationText(result.prepare.timeout)}, ${result.prepare.attach.files} files`)
|
|
159
144
|
if (result.writes?.length) line('writes', result.writes.map(w => `${w.name} → ${w.path}`).join(', '))
|
|
160
145
|
if (result.memory) line('memory', `${result.memory.backend} push ${result.memory.push} pull ${result.memory.pull}`)
|
|
161
146
|
line('messages', `${result.messages}${result.waiting ? ` (${result.waiting} waiting)` : ''}`)
|
|
@@ -185,7 +170,7 @@ function renderShow (result) {
|
|
|
185
170
|
if (result.plugins.length) line('plugins', result.plugins.join(', '))
|
|
186
171
|
if (result.differs.length) line('docs', `${result.differs.join(', ')} differ from what is installed — spore upgrade ${basename(result.ws)}`)
|
|
187
172
|
const { disk } = result
|
|
188
|
-
line('disk', `${
|
|
173
|
+
line('disk', `${bytesText(disk.total)} — data ${bytesText(disk.data)} · records ${bytesText(disk.state)} · streams ${bytesText(disk.calls)} · sent ${bytesText(disk.inbox)} · other ${bytesText(disk.other)}`)
|
|
189
174
|
for (const [i, one] of result.schedules.entries()) line(i ? '' : 'schedules', scheduleLine(one))
|
|
190
175
|
if (result.scheduleBound) {
|
|
191
176
|
const b = result.scheduleBound
|
|
@@ -477,7 +462,6 @@ function renderPlugin (result) {
|
|
|
477
462
|
line(i ? '' : 'settings', `${key} (${kind})${result.configured?.[key] === undefined ? '' : ` = ${result.configured[key]}`}`)
|
|
478
463
|
}
|
|
479
464
|
for (const [i, [name, path]] of Object.entries(result.programs).entries()) line(i ? '' : 'programs', `${name} → ${path}`)
|
|
480
|
-
for (const [i, [name, path]] of Object.entries(result.routes).entries()) line(i ? '' : 'routes', `${name} → ${path}, an owner's router (hooks.json)`)
|
|
481
465
|
for (const [i, [name, value]] of Object.entries(result.env).entries()) line(i ? '' : 'env', `${name}=${value}`)
|
|
482
466
|
if (result.contain) line('contain', result.contain.keep ? `${result.contain.keep}, and nothing else of ${result.contain.hide}` : `nothing of ${result.contain.hide}`)
|
|
483
467
|
if (result.modules.length) line('modules', `${result.modules.join(', ')} → node_modules/, for the agent's programs`)
|
|
@@ -724,7 +708,7 @@ export async function manage (verb, argv) {
|
|
|
724
708
|
stopped = stopJob({ ws, name })
|
|
725
709
|
} catch (err) {
|
|
726
710
|
if (err.type !== 'JOB_NOT_RUNNING') throw err
|
|
727
|
-
console.error(`spore: ${err
|
|
711
|
+
console.error(`spore: ${errorText(err)}`)
|
|
728
712
|
return 1
|
|
729
713
|
}
|
|
730
714
|
return emit(stopped, (r) => { console.log(`asked the supervisor of ${r.name} (pid ${r.pid}) to stop it — how it ended is said to the spore`) })
|
|
@@ -774,7 +758,7 @@ export async function manage (verb, argv) {
|
|
|
774
758
|
return 2
|
|
775
759
|
}
|
|
776
760
|
return emit(remove({ ws: name, yes: argv.yes }), (r) => {
|
|
777
|
-
console.log(`removed ${r.ws} — ${r.turns} turn(s), $${r.treeUsd.toFixed(4)}, ${
|
|
761
|
+
console.log(`removed ${r.ws} — ${r.turns} turn(s), $${r.treeUsd.toFixed(4)}, ${bytesText(r.bytes)}`)
|
|
778
762
|
})
|
|
779
763
|
}
|
|
780
764
|
if (verb === 'usage') {
|
|
@@ -798,7 +782,7 @@ export async function manage (verb, argv) {
|
|
|
798
782
|
})
|
|
799
783
|
}
|
|
800
784
|
} catch (err) {
|
|
801
|
-
console.error(`spore: ${err
|
|
785
|
+
console.error(`spore: ${errorText(err)}`)
|
|
802
786
|
return 2
|
|
803
787
|
}
|
|
804
788
|
}
|
package/src/hooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { durationText, listHooks, showHook } from '@rhizogrip/spore'
|
|
1
|
+
import { durationText, listHooks, showHook, sizeSpelling } from '@rhizogrip/spore'
|
|
2
2
|
|
|
3
3
|
import { createServices } from './services.js'
|
|
4
4
|
|
|
@@ -6,8 +6,6 @@ const JOURNAL_LINES = 20
|
|
|
6
6
|
const ANSWER_CHARS = 120
|
|
7
7
|
const UNAVAILABLE = new Set(['SERVICE_NO_SYSTEMD', 'SERVICE_NOT_DEFINED'])
|
|
8
8
|
|
|
9
|
-
const kb = (bytes) => bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)}MB` : `${Math.round(bytes / 1024)}KB`
|
|
10
|
-
|
|
11
9
|
const verifyText = ({ method, header }) => header ? `${method} on ${header}` : method
|
|
12
10
|
|
|
13
11
|
const acceptText = (accept) => [
|
|
@@ -46,15 +44,11 @@ function renderHook (hook) {
|
|
|
46
44
|
console.log(`${hook.name} — ${hook.path}`)
|
|
47
45
|
console.log(` verify ${verifyText(hook.verify)}`)
|
|
48
46
|
if (hook.accept) console.log(` accepts ${acceptText(hook.accept)}`)
|
|
49
|
-
console.log(` bounds ${
|
|
50
|
-
if (hook.owner) {
|
|
51
|
-
const { plugin, name, timeoutMs, attach, reads } = hook.owner
|
|
52
|
-
console.log(` router ${plugin}/${name}, the owner's: attaches up to ${attach.files} files and ${kb(attach.bytes)} within ${durationText(timeoutMs)}${reads === 'spore' ? ', reading what the spore\'s reads: grant' : reads.length ? `, reading ${reads.join(', ')}` : ''}`)
|
|
53
|
-
}
|
|
47
|
+
console.log(` bounds ${sizeSpelling(hook.maxBytes)} a request · ${hook.perHour} turns an hour · ${hook.maxWait ? `waits up to ${durationText(hook.maxWait)}` : 'never waits'} · ${hook.perDay} triage cells a day`)
|
|
54
48
|
for (const spore of hook.spores) {
|
|
55
49
|
console.log(`\n${sporeLine(spore, spore.name.length)}`)
|
|
56
50
|
if (!spore.ws) continue
|
|
57
|
-
if (spore.router) console.log(` router ${spore.router}
|
|
51
|
+
if (spore.router) console.log(` router ${spore.router}`)
|
|
58
52
|
if (spore.triage) console.log(` triage ${spore.triage}`)
|
|
59
53
|
for (const held of spore.held) console.log(` held since ${held.at}, released ${held.releaseAt}, at the latest ${held.deadline}${held.summary ? ` — ${held.summary}` : ''}`)
|
|
60
54
|
for (const d of spore.deliveries) {
|
package/src/services.js
CHANGED
|
@@ -19,7 +19,7 @@ import { createRequire } from 'node:module'
|
|
|
19
19
|
import { homedir, userInfo } from 'node:os'
|
|
20
20
|
import { dirname, join } from 'node:path'
|
|
21
21
|
|
|
22
|
-
import { CONFIG_DIR, pluginRoots, pluginServices, SERVICE_STATE_DIR, SporeError, versionAt } from '@rhizogrip/spore'
|
|
22
|
+
import { CONFIG_DIR, NAMES, pluginRoots, pluginServices, SERVICE_STATE_DIR, SporeError, versionAt } from '@rhizogrip/spore'
|
|
23
23
|
|
|
24
24
|
const SPORE_PACKAGE = '@rhizogrip/spore'
|
|
25
25
|
const ROOT = dirname(createRequire(import.meta.url).resolve(`${SPORE_PACKAGE}/package.json`))
|
|
@@ -33,6 +33,22 @@ const MARKER = 'X-Spore-Service'
|
|
|
33
33
|
|
|
34
34
|
const quoted = (path) => `"${path}"`
|
|
35
35
|
|
|
36
|
+
/** A Node program's unit, restarted when it fails and never after it refuses with exit 2. */
|
|
37
|
+
const nodeUnit = ({ description, marker, node, program, args = '' }) => [
|
|
38
|
+
'[Unit]',
|
|
39
|
+
`Description=${description}`,
|
|
40
|
+
`${MARKER}=${marker}`,
|
|
41
|
+
'',
|
|
42
|
+
'[Service]',
|
|
43
|
+
`ExecStart=${quoted(node)} ${quoted(program)}${args}`,
|
|
44
|
+
'Restart=on-failure',
|
|
45
|
+
'RestartPreventExitStatus=2',
|
|
46
|
+
'KillMode=process',
|
|
47
|
+
'',
|
|
48
|
+
'[Install]',
|
|
49
|
+
'WantedBy=default.target'
|
|
50
|
+
]
|
|
51
|
+
|
|
36
52
|
/**
|
|
37
53
|
* The keys the ssh-agent service loads: every private key in this folder beside `config.json`,
|
|
38
54
|
* never inside a workspace, so no spore can read one. Adding or retiring a key is putting it in
|
|
@@ -83,20 +99,7 @@ export const SERVICES = Object.freeze({
|
|
|
83
99
|
check: ({ node, root }) => [node, [join(root, 'bin', 'spore-webhook.js'), '--check']],
|
|
84
100
|
next: () => 'give each sender http://<host>/hook/<name> through your reverse proxy — it listens on 127.0.0.1:8742, or SPORE_WEBHOOK_LISTEN in environment',
|
|
85
101
|
units: ({ node, root }) => ({
|
|
86
|
-
'spore-webhook.service':
|
|
87
|
-
'[Unit]',
|
|
88
|
-
'Description=spore-webhook: webhooks as messages to spores',
|
|
89
|
-
`${MARKER}=webhook`,
|
|
90
|
-
'',
|
|
91
|
-
'[Service]',
|
|
92
|
-
`ExecStart=${quoted(node)} ${quoted(join(root, 'bin', 'spore-webhook.js'))}`,
|
|
93
|
-
'Restart=on-failure',
|
|
94
|
-
'RestartPreventExitStatus=2',
|
|
95
|
-
'KillMode=process',
|
|
96
|
-
'',
|
|
97
|
-
'[Install]',
|
|
98
|
-
'WantedBy=default.target'
|
|
99
|
-
]
|
|
102
|
+
'spore-webhook.service': nodeUnit({ description: 'spore-webhook: webhooks as messages to spores', marker: 'webhook', node, program: join(root, 'bin', 'spore-webhook.js') })
|
|
100
103
|
})
|
|
101
104
|
},
|
|
102
105
|
api: {
|
|
@@ -107,20 +110,7 @@ export const SERVICES = Object.freeze({
|
|
|
107
110
|
check: ({ node, root }) => [node, [join(root, 'bin', 'spore-api.js'), '--check']],
|
|
108
111
|
next: () => 'give each caller its token and the socket or address api.json names',
|
|
109
112
|
units: ({ node, root }) => ({
|
|
110
|
-
'spore-api.service':
|
|
111
|
-
'[Unit]',
|
|
112
|
-
'Description=spore-api: the library\'s verbs over HTTP',
|
|
113
|
-
`${MARKER}=api`,
|
|
114
|
-
'',
|
|
115
|
-
'[Service]',
|
|
116
|
-
`ExecStart=${quoted(node)} ${quoted(join(root, 'bin', 'spore-api.js'))}`,
|
|
117
|
-
'Restart=on-failure',
|
|
118
|
-
'RestartPreventExitStatus=2',
|
|
119
|
-
'KillMode=process',
|
|
120
|
-
'',
|
|
121
|
-
'[Install]',
|
|
122
|
-
'WantedBy=default.target'
|
|
123
|
-
]
|
|
113
|
+
'spore-api.service': nodeUnit({ description: 'spore-api: the library\'s verbs over HTTP', marker: 'api', node, program: join(root, 'bin', 'spore-api.js') })
|
|
124
114
|
})
|
|
125
115
|
},
|
|
126
116
|
'ssh-agent': {
|
|
@@ -218,20 +208,7 @@ function fromPlugin (found) {
|
|
|
218
208
|
runs: named,
|
|
219
209
|
check: found.check && (({ node, instance }) => [node, [found.program, ...(instance === null ? [] : [instance]), ...found.check]]),
|
|
220
210
|
units: ({ node }) => ({
|
|
221
|
-
[unit]:
|
|
222
|
-
'[Unit]',
|
|
223
|
-
`Description=spore-${found.name}${instance}: ${found.what.replaceAll('%', '%%')}`,
|
|
224
|
-
`${MARKER}=${found.name}`,
|
|
225
|
-
'',
|
|
226
|
-
'[Service]',
|
|
227
|
-
`ExecStart=${quoted(node)} ${quoted(found.program)}${instance}`,
|
|
228
|
-
'Restart=on-failure',
|
|
229
|
-
'RestartPreventExitStatus=2',
|
|
230
|
-
'KillMode=process',
|
|
231
|
-
'',
|
|
232
|
-
'[Install]',
|
|
233
|
-
'WantedBy=default.target'
|
|
234
|
-
]
|
|
211
|
+
[unit]: nodeUnit({ description: `spore-${found.name}${instance}: ${found.what.replaceAll('%', '%%')}`, marker: found.name, node, program: found.program, args: instance })
|
|
235
212
|
})
|
|
236
213
|
}
|
|
237
214
|
}
|
|
@@ -274,8 +251,6 @@ function serviceOf (name, catalog) {
|
|
|
274
251
|
return service
|
|
275
252
|
}
|
|
276
253
|
|
|
277
|
-
const INSTANCE = /^[a-z0-9][a-z0-9._-]*$/i
|
|
278
|
-
|
|
279
254
|
/**
|
|
280
255
|
* `telegram@reviewer` is the service `telegram`, its instance `reviewer`. `verb` is the `spore
|
|
281
256
|
* service` subcommand it was named to, for the command a refusal suggests.
|
|
@@ -294,8 +269,8 @@ function parsed (name, catalog, { instanceOptional = false, verb } = {}) {
|
|
|
294
269
|
detail: `spore service ${verb} ${base}@<${service.instances.called}>, for the ${service.instances.called} in ${service.instances.dir}/<${service.instances.called}>${service.instances.ext} beside config.json`
|
|
295
270
|
})
|
|
296
271
|
}
|
|
297
|
-
if (instance !== null && !
|
|
298
|
-
throw new SporeError(`"${instance}" cannot be a ${service.instances.called}'s name`, { type: 'SERVICE_UNKNOWN', detail:
|
|
272
|
+
if (instance !== null && !NAMES.bot.pattern.test(instance)) {
|
|
273
|
+
throw new SporeError(`"${instance}" cannot be a ${service.instances.called}'s name`, { type: 'SERVICE_UNKNOWN', detail: NAMES.bot.says })
|
|
299
274
|
}
|
|
300
275
|
return { base, instance, service }
|
|
301
276
|
}
|
package/tui/conversation.js
CHANGED
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
* events arrive. Pure: records and events in, items out.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { asked, originLabel } from '@rhizogrip/spore'
|
|
8
|
+
|
|
7
9
|
import { printable } from './printable.js'
|
|
8
10
|
|
|
9
|
-
/** Who said an entry, when that is known: a person by name, or
|
|
11
|
+
/** Who said an entry, when that is known: a person by name, or what said it when no person did. */
|
|
10
12
|
export function saidBy (entry) {
|
|
11
13
|
if (entry.fromName) return printable(entry.fromName)
|
|
12
|
-
|
|
13
|
-
if (entry.hook) return `webhook "${entry.hook}"`
|
|
14
|
-
if (entry.job) return `job "${entry.job}"`
|
|
15
|
-
return null
|
|
14
|
+
return originLabel(entry)
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
export function originOf (entry) {
|
|
@@ -33,7 +32,7 @@ const said = (entry) => ({ kind: 'said', inboxNo: entry.inboxNo, origin: originO
|
|
|
33
32
|
export function history ({ turns, inbox }) {
|
|
34
33
|
const items = []
|
|
35
34
|
for (const turn of turns) {
|
|
36
|
-
for (const entry of
|
|
35
|
+
for (const entry of asked(turn, inbox)) items.push(said(entry))
|
|
37
36
|
if (turn.output) items.push({ kind: 'answer', text: printable(turn.output) })
|
|
38
37
|
items.push({
|
|
39
38
|
kind: 'end',
|
|
@@ -46,7 +45,7 @@ export function history ({ turns, inbox }) {
|
|
|
46
45
|
durationMs: turn.startedAt && turn.endedAt ? Date.parse(turn.endedAt) - Date.parse(turn.startedAt) : null
|
|
47
46
|
})
|
|
48
47
|
}
|
|
49
|
-
for (const entry of inbox.filter(e => !e.consumed &&
|
|
48
|
+
for (const entry of inbox.filter(e => !e.consumed && e.asks)) items.push({ ...said(entry), waiting: true })
|
|
50
49
|
return items
|
|
51
50
|
}
|
|
52
51
|
|
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, 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, 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'
|
|
@@ -421,7 +421,7 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
421
421
|
try {
|
|
422
422
|
sent = send(state.ws, text, { replyTo: 'terminal' })
|
|
423
423
|
} catch (err) {
|
|
424
|
-
return notice(err
|
|
424
|
+
return notice(errorText(err))
|
|
425
425
|
}
|
|
426
426
|
editor.addToHistory(text)
|
|
427
427
|
notice(sent.started ? 'started a turn' : 'heard — the running turn reads it next')
|
|
@@ -435,7 +435,7 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
435
435
|
state.limits = show({ ws: state.ws }).turnLimits
|
|
436
436
|
refresh()
|
|
437
437
|
} catch (err) {
|
|
438
|
-
notice(err
|
|
438
|
+
notice(errorText(err))
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
|
|
@@ -453,7 +453,7 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
453
453
|
notice(switched.was === switched.model ? `already runs on ${switched.model}` : `runs on ${switched.model} from the next turn`)
|
|
454
454
|
refresh()
|
|
455
455
|
} catch (err) {
|
|
456
|
-
notice(err
|
|
456
|
+
notice(errorText(err))
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
if (args.length) return switchTo(args[0])
|