@rhizogrip/spore-cli 1.30.0 → 1.31.1
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/package.json +2 -2
- package/tui/README.md +1 -0
- package/tui/index.js +17 -4
- package/tui/links.js +29 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhizogrip/spore-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
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.31.1",
|
|
54
54
|
"chalk": "^6.0.1",
|
|
55
55
|
"minimist": "^1.2.8"
|
|
56
56
|
},
|
package/tui/README.md
CHANGED
|
@@ -13,6 +13,7 @@ alt+enter a new line
|
|
|
13
13
|
ctrl+p open another spore
|
|
14
14
|
ctrl+o tool calls in full — an edit or a write as its diff
|
|
15
15
|
alt+c copy the last code block of the last answer, exactly as written
|
|
16
|
+
click the `· /copy <n>` on a code block's opening fence copies that block
|
|
16
17
|
ctrl+g write the message in $EDITOR
|
|
17
18
|
esc esc stop the running turn; when none runs, clear the line
|
|
18
19
|
ctrl+c clear the line
|
package/tui/index.js
CHANGED
|
@@ -4,13 +4,14 @@ 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, stateOf, stop, switchModel, unpause, upstream, watchAll, wrapTurn } from '@rhizogrip/spore'
|
|
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'
|
|
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
12
|
import { history, markOf } from './conversation.js'
|
|
13
13
|
import { changeOf, counts, hunks } from './diff.js'
|
|
14
|
+
import { copyNumber, fenceLabel } from './links.js'
|
|
14
15
|
import { printable } from './printable.js'
|
|
15
16
|
import { PromptEditor } from './prompt.js'
|
|
16
17
|
import { Answer } from './answer.js'
|
|
@@ -38,7 +39,7 @@ const markdownTheme = {
|
|
|
38
39
|
linkUrl: dim,
|
|
39
40
|
code: chalk.yellow,
|
|
40
41
|
codeBlock: (s) => s,
|
|
41
|
-
codeBlockBorder: dim,
|
|
42
|
+
codeBlockBorder: (label) => fenceLabel(label, dim),
|
|
42
43
|
quote: chalk.italic,
|
|
43
44
|
quoteBorder: dim,
|
|
44
45
|
hr: dim,
|
|
@@ -279,7 +280,7 @@ const ago = (iso, now) => (iso ? `${durationText(now - Date.parse(iso))} ago` :
|
|
|
279
280
|
* null for the default; `greeting` is a line shown as the screen opens.
|
|
280
281
|
*/
|
|
281
282
|
export async function runTui ({ ws, commands = [], renderTool = null, greeting = null, terminal = new ProcessTerminal() }) {
|
|
282
|
-
const tui = new TuiAltScreen(terminal)
|
|
283
|
+
const tui = new TuiAltScreen(terminal, undefined, undefined, { openUrl: copiedByLink })
|
|
283
284
|
const conversation = new Conversation({ renderTool })
|
|
284
285
|
const status = new StatusLine()
|
|
285
286
|
const editor = new PromptEditor(tui, editorTheme)
|
|
@@ -403,6 +404,18 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
403
404
|
if (await tui.copyTextToClipboard(text)) notice(`copied ${what}`)
|
|
404
405
|
}
|
|
405
406
|
|
|
407
|
+
/**
|
|
408
|
+
* A click on a code block's `· /copy <n>` label, which is drawn as a link carrying
|
|
409
|
+
* `spore-copy:<n>`: the same as typing `/copy <n>`.
|
|
410
|
+
*/
|
|
411
|
+
function copiedByLink (url) {
|
|
412
|
+
const n = copyNumber(url)
|
|
413
|
+
if (n === null) return
|
|
414
|
+
const block = conversation.lastBlocks()[n - 1]
|
|
415
|
+
if (!block) return notice(`the last answer has no code block ${n}`)
|
|
416
|
+
return copy(block.text, `code block ${n}`)
|
|
417
|
+
}
|
|
418
|
+
|
|
406
419
|
const say = (text) => {
|
|
407
420
|
let sent
|
|
408
421
|
try {
|
|
@@ -597,7 +610,7 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
|
|
|
597
610
|
})
|
|
598
611
|
|
|
599
612
|
const follow = async () => {
|
|
600
|
-
for await (const item of watchAll(
|
|
613
|
+
for await (const item of watchAll(sporePaths, { signal: following.signal })) {
|
|
601
614
|
if (item.ws === state.ws) {
|
|
602
615
|
if (item.event) {
|
|
603
616
|
if (item.event.seq <= state.lastSeq) continue
|
package/tui/links.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `· /copy <n>` label on a code block's opening fence, made a link. It is drawn as an OSC 8
|
|
3
|
+
* hyperlink — which kitty underlines on hover — so a click on it reaches pi-tui's `openUrl` with a
|
|
4
|
+
* URL this module reads back into the number of the block to copy. The label's own look is
|
|
5
|
+
* unchanged, and the link adds no width to the line.
|
|
6
|
+
*/
|
|
7
|
+
import { getCapabilities, hyperlink } from '@earendil-works/pi-tui'
|
|
8
|
+
|
|
9
|
+
const LABEL = /^(.*) · \/copy (\d+)$/
|
|
10
|
+
const SCHEME = 'spore-copy:'
|
|
11
|
+
|
|
12
|
+
/** The URL a labelled fence carries, or null for a label that names no block. */
|
|
13
|
+
export const copyUrl = (label) => {
|
|
14
|
+
const numbered = LABEL.exec(String(label))
|
|
15
|
+
return numbered ? `${SCHEME}${numbered[2]}` : null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The block number a clicked URL names, or null when the URL is not one of ours. */
|
|
19
|
+
export const copyNumber = (url) => {
|
|
20
|
+
if (!String(url).startsWith(SCHEME)) return null
|
|
21
|
+
const n = Number(String(url).slice(SCHEME.length))
|
|
22
|
+
return Number.isInteger(n) && n >= 1 ? n : null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** A fence label, styled and linked when the terminal shows hyperlinks, and left alone when not. */
|
|
26
|
+
export const fenceLabel = (label, style) => {
|
|
27
|
+
const url = copyUrl(label)
|
|
28
|
+
return url && getCapabilities().hyperlinks ? hyperlink(style(label), url) : style(label)
|
|
29
|
+
}
|