@rhizogrip/spore-cli 1.58.1 → 1.58.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-cli",
3
- "version": "1.58.1",
3
+ "version": "1.58.2",
4
4
  "author": {
5
5
  "name": "Christophe Le Bars",
6
6
  "email": "clb@toort.net"
@@ -54,7 +54,7 @@
54
54
  "minimist": "^1.2.8"
55
55
  },
56
56
  "optionalDependencies": {
57
- "@rhizogrip/spore": "1.58.1"
57
+ "@rhizogrip/spore": "1.58.2"
58
58
  },
59
59
  "license": "Apache-2.0"
60
60
  }
package/tui/README.md CHANGED
@@ -14,6 +14,8 @@ 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
16
  click the `· /copy <n>` on a code block's opening fence copies that block
17
+ click any other link copies where it points: a file by its full path, a web address as it is
18
+ shift+click a delivered file's path: left to the terminal, which can open it
17
19
  ctrl+g write the message in $EDITOR
18
20
  esc esc stop the running turn; when none runs, clear the line
19
21
  ctrl+c clear the line
@@ -4,10 +4,14 @@
4
4
  * events arrive. Pure: records and events in, items out.
5
5
  */
6
6
 
7
+ import { join } from 'node:path'
8
+
7
9
  import { asked, originLabel } from '@rhizogrip/spore'
8
10
 
9
11
  import { printable } from './printable.js'
10
12
 
13
+ const MOST_FILES_SHOWN = 5
14
+
11
15
  /** Who said an entry, when that is known: a person by name, or what said it when no person did. */
12
16
  export function saidBy (entry) {
13
17
  if (entry.fromName) return printable(entry.fromName)
@@ -28,12 +32,18 @@ export function saidText (entry) {
28
32
 
29
33
  const said = (entry) => ({ kind: 'said', inboxNo: entry.inboxNo, origin: originOf(entry), text: saidText(entry), at: entry.at })
30
34
 
31
- /** The finished turns, then what no turn has read yet. */
32
- export function history ({ turns, inbox }) {
35
+ /** The finished turns of the spore at `ws`, then what no turn has read yet. */
36
+ export function history ({ ws, turns, inbox }) {
33
37
  const items = []
34
38
  for (const turn of turns) {
35
39
  for (const entry of asked(turn, inbox)) items.push(said(entry))
36
40
  if (turn.output) items.push({ kind: 'answer', text: printable(turn.output) })
41
+ // A turn that never ran has no list, its record being written elsewhere.
42
+ const handed = turn.deliverables ?? []
43
+ if (handed.length) {
44
+ const files = handed.slice(0, MOST_FILES_SHOWN).map(file => ({ path: join(ws, file.path), bytes: file.bytes }))
45
+ items.push({ kind: 'delivered', files, more: handed.length - files.length + (turn.deliverablesMore ?? 0) })
46
+ }
37
47
  items.push({
38
48
  kind: 'end',
39
49
  turnNo: turn.turnNo,
package/tui/index.js CHANGED
@@ -12,7 +12,7 @@ import { withMoHint } from '../src/mo.js'
12
12
  import { COMMANDS, parseCommand } from './commands.js'
13
13
  import { history, markOf } from './conversation.js'
14
14
  import { changeOf, counts, hunks } from './diff.js'
15
- import { copyNumber, fenceLabel } from './links.js'
15
+ import { copyNumber, deliveredLine, fenceLabel, fileOf } from './links.js'
16
16
  import { printable } from './printable.js'
17
17
  import { PromptEditor } from './prompt.js'
18
18
  import { Answer } from './answer.js'
@@ -130,6 +130,10 @@ class Conversation {
130
130
  const answer = this.markdown(item)
131
131
  answer.label(item === last)
132
132
  out.push('', ...answer.render(width))
133
+ } else if (item.kind === 'delivered') {
134
+ out.push('')
135
+ for (const file of item.files) out.push(...lines(deliveredLine(file), width))
136
+ if (item.more) out.push(dim(`and ${item.more} more in data/out/`))
133
137
  } else if (item.kind === 'end') {
134
138
  const how = [item.stopReason, item.error].filter(Boolean).join(' · ')
135
139
  const took = item.durationMs === null ? '' : ` · ${durationText(item.durationMs)}`
@@ -353,7 +357,7 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
353
357
  }
354
358
 
355
359
  const reload = () => {
356
- conversation.items = history({ turns: readTurns(state.ws), inbox: readInbox(state.ws) })
360
+ conversation.items = history({ ws: state.ws, turns: readTurns(state.ws), inbox: readInbox(state.ws) })
357
361
  conversation.live = null
358
362
  state.limits = null
359
363
  const running = liveIn(state.ws)
@@ -448,15 +452,21 @@ export async function runTui ({ ws, commands = [], renderTool = null, greeting =
448
452
  }
449
453
 
450
454
  /**
451
- * A click on a code block's `· /copy <n>` label, which is drawn as a link carrying
452
- * `spore-copy:<n>`: the same as typing `/copy <n>`.
455
+ * A click on a link. On a code block's `· /copy <n>` label, which carries `spore-copy:<n>`, it is
456
+ * the same as typing `/copy <n>`. Any other link copies where it points, since the terminal shows
457
+ * only its text, and this screen may be running on another machine than the one clicked on.
453
458
  */
454
459
  function copiedByLink (url) {
455
460
  const n = copyNumber(url)
456
- if (n === null) return
457
- const block = conversation.lastBlocks()[n - 1]
458
- if (!block) return notice(`the last answer has no code block ${n}`)
459
- return copy(block.text, `code block ${n}`)
461
+ if (n !== null) {
462
+ const block = conversation.lastBlocks()[n - 1]
463
+ if (!block) return notice(`the last answer has no code block ${n}`)
464
+ return copy(block.text, `code block ${n}`)
465
+ }
466
+ const file = fileOf(url, state.ws)
467
+ if (file !== null && !existsSync(file)) return notice(`no file at ${printable(file)}`)
468
+ const target = file ?? url
469
+ return copy(target, printable(target))
460
470
  }
461
471
 
462
472
  const say = (text) => {
package/tui/links.js CHANGED
@@ -1,10 +1,16 @@
1
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, 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.
2
+ * The links the terminal draws and reads back. They are OSC 8 hyperlinks, so a click reaches
3
+ * pi-tui's `openUrl`, and they add no width to a line. The `· /copy <n>` label on a code block's
4
+ * opening fence carries the number of the block to copy; a delivered file carries its `file:` URL,
5
+ * which the terminal itself can open on Shift-click.
6
6
  */
7
+ import { fileURLToPath, pathToFileURL } from 'node:url'
8
+
7
9
  import { getCapabilities, hyperlink } from '@earendil-works/pi-tui'
10
+ import { bytesText } from '@rhizogrip/spore'
11
+ import chalk from 'chalk'
12
+
13
+ import { printable } from './printable.js'
8
14
 
9
15
  const LABEL = /^(.*) · \/copy (\d+)$/
10
16
  const SCHEME = 'spore-copy:'
@@ -27,3 +33,23 @@ export const fenceLabel = (label, style) => {
27
33
  const url = copyUrl(label)
28
34
  return url && getCapabilities().hyperlinks ? hyperlink(style(label), url) : style(label)
29
35
  }
36
+
37
+ /** A file the turn handed back, as a line: its full path, linked when the terminal shows hyperlinks. */
38
+ export const deliveredLine = ({ path, bytes }) => {
39
+ const shown = chalk.cyan(printable(path))
40
+ const linked = getCapabilities().hyperlinks ? hyperlink(shown, pathToFileURL(path).href) : shown
41
+ return `${chalk.dim('delivered')} ${linked} ${chalk.dim(bytesText(bytes))}`
42
+ }
43
+
44
+ /**
45
+ * The file a clicked link points at, a relative one read from the workspace `ws`; null for a link
46
+ * that names no file here. An answer's links are the model's own text, so one may not parse.
47
+ */
48
+ export const fileOf = (url, ws) => {
49
+ try {
50
+ const target = new URL(url, pathToFileURL(`${ws}/`))
51
+ return target.protocol === 'file:' ? fileURLToPath(target) : null
52
+ } catch {
53
+ return null
54
+ }
55
+ }